Good morning, when the player is dead or win the level, I want that the last game’s screen is displayed and also the guiTexture for display the score with the buttons if the user want to continue or repeat the level. How I can lock the game on the last screen and how can I do the animation for score etc over this screen ?
Thank you
When the player is dead, what about loading a separate “You Are Dead” scene?
If you want to freeze the gameplay scene instead, set Time.timeScale=0 (this will pause the game) and draw the score and buttons with Unity GUI. You could draw a semi-transparent black box on top of the screen before drawing the score and buttons. This will make the gameplay part look like it’s partially grayed out.
But if I set the Timescale =0 the GUI Animation will work ? I want that the Score and Buttons enter from the left side of the screen…
In this case, you can put Time in a wrapper class. For example:
public static class GameTime {
public bool paused = false;
public float deltaTime { get { return paused ? 0 : Time.deltaTime; } }
}
In your gameplay code, replace Time.deltaTime with GameTime.deltaTime. When you need to pause the game, use GameTime.paused = true instead of Time.timeScale = 0.
But 2ith this method I must put the code if (GameTime.paused) in every c# file into Update / FixedUpdate and OnGui method?
No. You only need to set GameTime.paused = true when the player dies or wins. This pauses the game. Then set GameTime.paused = false to resume the game after you’ve loaded the next level.
You do, however, need to replace Time.deltaTime with GameTime.deltaTime wherever you use it in your C# scripts.
Another approach is to pause the game with Time.timeScale = 0, and then manually advance the GUI animation using Time.realtimeSinceStartup. This way you don’t need to modify your other C# scripts. But it’s more work to play the GUI animation.