A have 16 cubs and I want to smoothly change it’s color one by one like here: SPINE on Vimeo .
But here what I have: - YouTube
What is wrong?
public float delay;
bool shouldCallFuncAtFirstTime;
bool shouldStartCoroutineAgain;
Renderer renderer;
Material mat;
void Start()
{
renderer = GetComponent<Renderer>();
mat = renderer.material;
shouldStartCoroutineAgain = true;
}
void Update()
{
StartCoroutine("ChangeMaterialDelay");
if (shouldCallFuncAtFirstTime)
ChangeMaterial();
}
void ChangeMaterial()
{
float emission = Mathf.PingPong(Time.time, 0.5f);
Color baseColor = Color.white;
Color finalColor = baseColor * Mathf.LinearToGammaSpace(emission);
mat.SetColor("_EmissionColor", finalColor);
shouldCallFuncAtFirstTime = false;
}
IEnumerator ChangeMaterialDelay()
{
if(shouldStartCoroutineAgain)
{
shouldStartCoroutineAgain = false;
yield return new WaitForSeconds(delay);
shouldCallFuncAtFirstTime = true;
shouldStartCoroutineAgain = true;
}
}