Search Unity

How to stop time on a specific prefab?

Discussion in 'Getting Started' started by Pollawat, Aug 17, 2017.

  1. Pollawat

    Pollawat

    Joined:
    Aug 27, 2016
    Posts:
    192
    For example, when I hit "A" I need everything stop like time freezing but except a camera.
    Another example like when you play some RTS game that can pause a time anyways you can still move a camera around.
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    In this case you don't muck about with Time.timeScale. Instead you just make your own global variable that indicates when the game is paused, and all your scripts that you want to pause, check this variable and bail out, e.g.:

    Code (csharp):
    1. void Update() {
    2.     if (PauseManager.isPaused) return;
    3.     // ...do stuff...
    4. }
    Of course this assumes you're not using the physics engine, which I generally recommend anyway. :)
     
    Kiwasi and Ryiah like this.
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    You can also use Time.unscaledDeltaTime for things that don't pause.
     
    eXonius and JoeStrout like this.