Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class RainbowColor : MonoBehaviour
- {
- [SerializeField] private float _hueShiftSpeed = 0.1f;
- [SerializeField, Range(0,1)] private float _saturation = 1f;
- [SerializeField, Range(0,1)] private float _value = 1f;
- private Image _button;
- public bool GoRainbow;
- void Start()
- {
- _button = GetComponent<Image>();
- }
- void Update()
- {
- if (!GoRainbow) return;
- float amountToShift = _hueShiftSpeed * 0.01f;
- Color newColor = ShiftHueBy(_button.color, amountToShift);
- _button.color = newColor;
- }
- private Color ShiftHueBy(Color color, float amount)
- {
- Color.RGBToHSV(color, out float hue, out float sat, out float val);
- hue += amount;
- sat = _saturation;
- val = _value;
- return Color.HSVToRGB(hue, sat, val);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment