Hi Guys,
Trying to make an object half opacity, then slowly come back over time. I’ve made an IENumerator to handle the event, but it’s coming back with a strange result.
IEnumerator SuperPill()
{
bSuperPill = true;
GameObject[] leukemias = GameObject.FindGameObjectsWithTag("Leukemia");
// Start
for(int i = 0; i < leukemias.Length; i++)
{
if(leukemias[i] != null)
{
Color colorEffect = leukemias[i].renderer.material.color;
colorEffect.a = 0.5f;
leukemias[i].GetComponent<LeukemiaAI>().Move_Speed = 0.0265f;
leukemias[i].renderer.material.color = colorEffect;
}
}
yield return new WaitForSeconds( (fSuperPillTime - 0.5f));
// Warn of end
leukemias = GameObject.FindGameObjectsWithTag("Leukemia");
for(float t = 0.5f; t < 1; t += Time.deltaTime)
{
for(int i = 0; i < leukemias.Length; i++)
{
Color colorEffect = leukemias[i].renderer.material.color;
colorEffect.a = t;
Debug.Log(t + " _ " + colorEffect + " _ " + leukemias[i].renderer.material.color);
leukemias[i].renderer.material.color = colorEffect;
}
}
// End
leukemias = GameObject.FindGameObjectsWithTag("Leukemia");
for(int i = 0; i < leukemias.Length; i++)
{
if(leukemias[i] != null)
{
Color colorEffect = leukemias[i].renderer.material.color;
colorEffect.a = 1;
leukemias[i].GetComponent<LeukemiaAI>().Move_Speed = 0.053f;
leukemias[i].renderer.material.color = colorEffect;
}
}
bSuperPill = false;
}
Basically they go to half opacity. Then ignore the actions of the second For statement (and the one nested inside that), and go straight to full opacity.
I’ve brought back the logs that SAY it’s working, but the funny thing is the logs only appear in the Console after the entire event has finished. They will not appear until the entire EINumerator has ended.
0.9307263 _ RGBA(1.000, 1.000, 1.000, 0.931) _ RGBA(1.000, 1.000, 1.000, 0.914)
UnityEngine.Debug:Log(Object)
<SuperPill>c__Iterator2:MoveNext() (at Assets/Code/GameInformation.cs:132)
0.9472927 _ RGBA(1.000, 1.000, 1.000, 0.947) _ RGBA(1.000, 1.000, 1.000, 0.931)
UnityEngine.Debug:Log(Object)
<SuperPill>c__Iterator2:MoveNext() (at Assets/Code/GameInformation.cs:132)
0.9638591 _ RGBA(1.000, 1.000, 1.000, 0.964) _ RGBA(1.000, 1.000, 1.000, 0.947)
UnityEngine.Debug:Log(Object)
<SuperPill>c__Iterator2:MoveNext() (at Assets/Code/GameInformation.cs:132)
0.9804255 _ RGBA(1.000, 1.000, 1.000, 0.980) _ RGBA(1.000, 1.000, 1.000, 0.964)
UnityEngine.Debug:Log(Object)
<SuperPill>c__Iterator2:MoveNext() (at Assets/Code/GameInformation.cs:132)
0.9969919 _ RGBA(1.000, 1.000, 1.000, 0.997) _ RGBA(1.000, 1.000, 1.000, 0.980)
UnityEngine.Debug:Log(Object)
<SuperPill>c__Iterator2:MoveNext() (at Assets/Code/GameInformation.cs:132)
Any ideas?
Thanks guys