using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Myclass: MonoBehaviour {
RectTransform rt;
Text txt;
public float fadeSpeed;
void Start () {
txt = gameObject.GetComponent<Text>(); // Accessing the text component
}
void Update () {
ColorChange();
}
void ColorChange()
{
txt.color = Color.Lerp (txt.color, txt.color, fadeSpeed * 5 * Time.deltaTime);
int random = Random.Range(1,5);
if(random==1)
txt.color=Color.red;
else if(random==2)
txt.color=Color.cyan;
else if(random==3)
txt.color=Color.magenta;
else if(random==4)
txt.color=Color.green;
}
}
Here The update keeps calling ColorChange everyframe and my Lerp is useless here because of this.
I want to save framerate and all of unnecessary resources wasted by these calls
Is there way i can optimize this by just calling my Colorchange every 3 or 5 seconds with Lerp working properly for lets say 3 seconds and changing the color slowly.
Please suggest some optimized way to save unnecessary calls to functions.
I had tried IEnumerator, waitforseconds, and then there is Invokerepeating But non of them seems to be working because of Update keep calling the changeColor.