Unity Nuggets: How to do "Hit Pause" or "Screen Freeze" in games

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ก.พ. 2025

ความคิดเห็น • 27

  • @IndieNuggets
    @IndieNuggets  5 ปีที่แล้ว +17

    Sorry there is a mistake at 1:03 . This should be "if (_pendingFreezeDuration > 0 && !_isFrozen)" not less than 0

  • @TestMyVidsOut
    @TestMyVidsOut 7 ปีที่แล้ว +7

    Love the style of your content, especially that clarification about WaitForSeconds vs. WaitForSecondsRealtime!

  • @joe6949
    @joe6949 5 ปีที่แล้ว +1

    Just found your tutorial. Great job explaining things! really helpful

  • @CoffeeCupPug
    @CoffeeCupPug 5 ปีที่แล้ว +1

    Very good explanation, thank you for this! :)

  • @RoroGames03
    @RoroGames03 6 ปีที่แล้ว +3

    Great Video!! Btw there is an error in the Freezer script in the update function it should be if(_pendingFreezeDuration > 0 && !_isFrozen) you typed < 0

  • @Maphis11
    @Maphis11 4 ปีที่แล้ว

    Hi there, thanks for posting!

  • @uhhh...
    @uhhh... 2 ปีที่แล้ว

    its can apply on player when get hit from enemy?

  • @dungensAreDragons
    @dungensAreDragons 5 ปีที่แล้ว

    I would just call Thread.Sleep(25) instead. One line and does that same thing (even easier as it wont mess up any pause or slo-mo script that handle the Timescale)

    • @IndieNuggets
      @IndieNuggets  5 ปีที่แล้ว

      Cool, but wouldn’t thread sleep block the main thread causing everything to stop. There are generally other time independent stuff going around in games which I don’t wanna stop.
      Also I’ve found that threads implementation at os level vary wildly.

  • @CloudC-kj6kt
    @CloudC-kj6kt 3 ปีที่แล้ว

    indian really talent at software

  • @roboeast6580
    @roboeast6580 5 ปีที่แล้ว

    How would you handle a pause menu (pausing the game) that doesn't conflict with this? If I paused the game during a hit, I am assuming this would break.

    • @IndieNuggets
      @IndieNuggets  5 ปีที่แล้ว

      For pause you can keep another variable like ‘gamePaused’ and if it’s true don’t simulate the game.
      I’m not sure what you mean by game breaking but you can always cancel any hit pauses IF/When the game is paused.

  • @paradoxicalenigma6119
    @paradoxicalenigma6119 5 ปีที่แล้ว

    Can you please add a tooltip/caption to correct the "if (_pendingFreezeDuration < 0 && !_isFrozen)" ? It can mess many people up since even though it looks weird we still will follow with the expectation that you know something that we don't.

    • @IndieNuggets
      @IndieNuggets  5 ปีที่แล้ว

      Yeah I'm really sorry about that. Seems TH-cam has deprecated the annotations feature so I couldn't add it at the mistake. For now I've added this in the description and tried putting a card at the top. Thanks

    • @paradoxicalenigma6119
      @paradoxicalenigma6119 5 ปีที่แล้ว +1

      @@IndieNuggets Thanks for that! Sorry for sounding critical, I just really liked your video. Other than that the code works great for me, so thanks for your help!

  • @dushyantsingh2624
    @dushyantsingh2624 5 ปีที่แล้ว

    Thanx a lot bro!! Awesome

  • @mathismeilby
    @mathismeilby 4 ปีที่แล้ว

    Hi there - when time freezes, I can still move my character which is giving me some trouble. Can anyone help me fix that?

  • @DiscipleKnight1010
    @DiscipleKnight1010 6 ปีที่แล้ว

    Thank you very much

  • @aborayan5268
    @aborayan5268 6 ปีที่แล้ว

    Thanks for this tuto, really i like your teacher method but one thing please keep this script editor for you next tutos, the new is not good for screen mobile, thank you again

  • @spaxhuxley302
    @spaxhuxley302 6 ปีที่แล้ว +1

    i'm having problems, the script itself doesn't work and I followed you carefully
    code:
    public class Friezar : MonoBehaviour {
    [Range(0f,1f)]
    public float duration = 1f;
    bool isFrozen = false;
    float pendingFreezeDuration = 0f;
    // Update is called once per frame
    void Update () {
    if (pendingFreezeDuration < 0 && !isFrozen)
    {
    StartCoroutine(DoFreeze());Debug.Log("frez");
    }
    }
    public void Freeze()
    {
    pendingFreezeDuration = duration;
    }
    IEnumerator DoFreeze()
    {
    isFrozen = true;
    var original = Time.timeScale;
    Time.timeScale = 0f;
    yield return new WaitForSecondsRealtime(duration);
    Time.timeScale = original;
    pendingFreezeDuration = 0;
    isFrozen = false;
    }
    }

    • @IndieNuggets
      @IndieNuggets  6 ปีที่แล้ว +6

      In your update method "if" condition the "pendingFreezeDuration" should be greater than zero not less than "if(pendingFreezeDuration>0 && !isFrozen)". :)

    • @spaxhuxley302
      @spaxhuxley302 6 ปีที่แล้ว +1

      thank you

    • @headbangstudio2443
      @headbangstudio2443 5 ปีที่แล้ว +1

      I had same problem, thank you.

    • @squali1930
      @squali1930 5 ปีที่แล้ว

      @@IndieNuggets In your video it says < 0 that's why we made the mistake. Thank you for correcting though.

  • @JoeAC5000
    @JoeAC5000 4 ปีที่แล้ว

    You lost me at 2:05 I don't know how to implement any of that stuff.

  • @jokesterthemighty227
    @jokesterthemighty227 7 ปีที่แล้ว

    lol