Hey guys. I want to make the alpha of an image blink two times within two seconds. I used a coroutine but stumbled upon some problems. First off, the code:
IEnumerator DepleteEnergy()
{
float endTime = 2f;
float executionTime = 0f;
while (executionTime < endTime)
{
if (GlobalMasterScript.GameState == GlobalMaster.GameStates.RaceInProgress)
{
executionTime += Time.deltaTime;
Color c = HealthFGImage.color;
c.a = Mathf.PingPong(executionTime * 2f, 1f);
HealthFGImage.color = c;
}
yield return null;
}
}
Now my problems:
1] The alpha value is set to 1 by default. Unfortunately, when the coroutine starts, it will immediately jump to 0 and climb up from there. It will eventually end with alpha at 0. I basically need to invert the PingPong value so it starts and ends with 1. How would I do that?
2] I need to pause the coroutine when the game is paused. When pausing the game, Time.timeScale is set to 0. You can see I tried to implement something in my coroutine to make the coroutine pause aswell but it is not working. How can I pause the coroutine and continue it properly when GameState changes/Time.timeScale is 1?
Thanks in advance