Hello I have a script that changes the color of an image over time. but i have to use the fixed update function for it to work properly i tried using a while loop but kept crashing the program when i used it. i would like to get the script to not be reliant on the fixed update function and would like to use a speed variable to affect the speed of the color transition for the rainbow effect but i am unsure how. here is the script below
public class ColorText : MonoBehaviour
{
[SerializeField]
private TextMeshProUGUI test;
public GameObject Panel;
public Image image;
public bool loop = false;
public int loopIndex = 0;
public Color[] characterColors =
{
//standard colors
new Color(0,0,0,0), //clear
new Color(0,0,0,1), //black
new Color(0,0,1,1), //blue
new Color(0,1,1,1), //cyan
new Color(0.5f,0.5f,0.5f,1), //gray
new Color(0,1,0,1), //green
new Color(1,0,1,1), //magenta
new Color(1,0,0,1), //red
new Color(1,1,1,1), //white
new Color(1,0.92f,0.016f,1), //yellow
//custom colors
//new Color(0,0,0,1), //color name
};
// Start is called before the first frame update
void Start()
{
image = GameObject.Find("Root").GetComponent<Image>();
}
// Update is called once per frame
void FixedUpdate()
{
Color();
}
private void Update()
{
if (Input.GetButtonDown("DownArrow"))
loop = true;
if (Input.GetButtonDown("UpArrow"))
loop = false;
}
void Color()
{
image.color = characterColors[loopIndex];
if(loopIndex >= characterColors.Length - 1 && loop)
{
loopIndex = 1;
}
if (loopIndex < characterColors.Length && loop)
{
loopIndex++;
}
}
}