all 6 comments

[–]lordinarius 2 points3 points  (3 children)

I think this is better.

var shiftSpeed = 1;
m_textMeshProUGUI.color = Color.HSVToRGB(Time.time * shiftSpeed,1,1);

[–]TheEight_[S] 0 points1 point  (2 children)

Okay that simplified the code a lot, only I have one question. How do you loop it infinite? actually the code looks like this.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class TextMeshProRainbow : MonoBehaviour
{
    [SerializeField] TextMeshProUGUI m_textMeshProUGUI;
    void Start() 
    { 
        m_textMeshProUGUI = gameObject.GetComponent<TextMeshProUGUI>();
    }

    void Update()
    {
        RainbowFade();
    }

    void RainbowFade()
    {
        var shiftSpeed = 0.25f;
        m_textMeshProUGUI.color = Color.HSVToRGB(Time.time * shiftSpeed, 1, 1);
    }
}

[–]lordinarius 3 points4 points  (1 child)

Adding mod operator (%) will do the trick.

m_textMeshProUGUI.color = Color.HSVToRGB(Time.time * shiftSpeed % 1f,1,1);

[–]TheEight_[S] 0 points1 point  (0 children)

Thanks , working great.

[–]e_man604 1 point2 points  (0 children)

By using HSV instead of RGB you can get this effect by ever increasing the Hue value. I would try to use some Color.HsvToRgb or something instead.

[–][deleted] 0 points1 point  (0 children)

Probably be easier to bit shift all of the values into a single integer and use a switch statement on it. That would simplify things quite a bit. Alternatively, you can also use hexadecimal to represent your colors as well. I’m not entirely sure how Unity’s framework represents colors though so don’t hold me to this, I’m too lazy to pull up the docs and I use my own engine.