-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextRainbow.cs
More file actions
32 lines (27 loc) · 978 Bytes
/
TextRainbow.cs
File metadata and controls
32 lines (27 loc) · 978 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using TMPro;
using UnityEngine;
namespace Agricosmic.Utilities
{
/// <summary>
/// Changes the color of text over the time in a rainbow!! :D
/// ✧∘* ✧・゚✧∘* ✧・゚✧∘* ✧・゚✧∘* ✧・゚✧∘* ✧・゚✧∘* ✧・゚
/// </summary>
public class TextRainbow : MonoBehaviour
{
[Tooltip("The speed to at which to cycle through the colors")]
[SerializeField] private float _speed = 0.2f;
[Tooltip("Reference to the text to modify. Located automatically if null at start-up")]
[SerializeField] private TMP_Text _text;
private float _time;
private void Start()
{
if (_text == null) _text = GetComponent<TMP_Text>();
}
// Update is called once per frame
private void Update()
{
_time += Time.deltaTime * _speed;
_text.color = Color.HSVToRGB(Mathf.Repeat(_time, 1f), 0.8f, 0.8f);
}
}
}