Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Scene after player dead or winner

Discussion in 'Scripting' started by FraMarSaMi, May 20, 2014.

  1. FraMarSaMi

    FraMarSaMi

    Joined:
    May 13, 2014
    Posts:
    86
    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
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    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.
     
  3. FraMarSaMi

    FraMarSaMi

    Joined:
    May 13, 2014
    Posts:
    86
    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...
     
  4. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    In this case, you can put Time in a wrapper class. For example:
    Code (csharp):
    1.  
    2. public static class GameTime {
    3.     public bool paused = false;
    4.     public float deltaTime { get { return paused ? 0 : Time.deltaTime; }  }
    5. }
    6.  
    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.
     
  5. FraMarSaMi

    FraMarSaMi

    Joined:
    May 13, 2014
    Posts:
    86
    But 2ith this method I must put the code if (GameTime.paused) in every c# file into Update / FixedUpdate and OnGui method?
     
  6. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    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.