Eonirr

Untitled

Apr 6th, 2023
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class RainbowColor : MonoBehaviour
  7. {
  8. [SerializeField] private float _hueShiftSpeed = 0.1f;
  9. [SerializeField, Range(0,1)] private float _saturation = 1f;
  10. [SerializeField, Range(0,1)] private float _value = 1f;
  11. private Image _button;
  12.  
  13. public bool GoRainbow;
  14.  
  15. void Start()
  16. {
  17. _button = GetComponent<Image>();
  18. }
  19. void Update()
  20. {
  21. if (!GoRainbow) return;
  22.  
  23. float amountToShift = _hueShiftSpeed * 0.01f;
  24. Color newColor = ShiftHueBy(_button.color, amountToShift);
  25. _button.color = newColor;
  26. }
  27.  
  28. private Color ShiftHueBy(Color color, float amount)
  29. {
  30. Color.RGBToHSV(color, out float hue, out float sat, out float val);
  31. hue += amount;
  32. sat = _saturation;
  33. val = _value;
  34. return Color.HSVToRGB(hue, sat, val);
  35. }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment