Mindzi
1
Hello I recently finished Survival shooter tutorial and I came across some problem. I want my game over text to fade in after i die so i wrote this into my update function
Color targetColor = new Color(255, 0, 0, 255);
if(isDead)
{
gameOver.color = Color.Lerp(gameOver.color, targetColor, 5f * Time.deltaTime);
}
the output of this is that there is no linear transition between color with no alpha and targetColor with alpha 255. What am I missing ? What is solution to make gameOver text slowly appear for 5 second after isDead condition is true ?
Thank you all for help
The last parameter of the Lerp works like a slider with 0 choosing the first parameter 100% and 1 the second 100%. If deltaTime was constant like fixedDeltaTime is and it nearly is, you’re basically passing in a constant and the resulting alpha is the same value every frame. What you need to do is have a float variable somewhere with a value of 0, increasing it every frame. So in your if statement you would put something like
yourFloat += Time.deltaTime / 5f;
this will increase yourFloat by a 5th of the passed time every frame essentially setting it to 1 and larger after 5 seconds.