Pause Your Game the Easy Way! (Unity Tutorial)

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ก.ค. 2024
  • In this Unity tutorial we're going to look at a really simple way to pause and resume a game.
    The project files are available to our patrons here:
    ► / 70967262
    Want to follow along? This project is a good starting point
    ► / project-files-to-68723927
    The final script can be found here
    ► dotnetfiddle.net/v7K4Pj
    Help support our work:
    ► Patreon: / ketragames
    ► Ko-fi: ko-fi.com/ketragames
    Follow us:
    ► Ketra Games: www.ketra-games.com
    ► Patreon: / ketragames
    ► Twitter: / ketragames
    ► Facebook: / ketragames
    Introduction - 0:00
    Creating the Initial Pause Script - 0:25
    Events on Pause and Resume - 2:42
    Using Unscaled Time to Prevent Objects From Pausing - 4:17
    Thanks - 05:30
    #KetraGames #LearnUnity #UnityTutorials #UnityTips

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

  • @BlueHat1
    @BlueHat1 ปีที่แล้ว +12

    Wow, this is such a great tutorial. This channel never disappoints❤

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

      Thanks for your support 😊

  • @shainachshon2166
    @shainachshon2166 ปีที่แล้ว +4

    My favorite Unity channel, everything is very clear and straight to the point.
    Could you possibly make tutorials about UI?
    Rect transform
    UI components in Unity and how to use them
    How you setup your UI
    maybe even instantiating UI because controlling UI from script is quite different from normal objects.
    Thank you for the amazing tips and tutorials!

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Thanks so much for this comment. We'll definitely be covering UI elements in the future 😊

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

    I watched this just to see if you showed unscaled time but honestly I found it neat that you used unity events for the paused game status. Good work.

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

    Really great tutorials, I'm all caught up now and checking out some of your other stuff. Cant wait to see where you take this, this truly is one of the better tutorials out there!

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Thanks so much for your support 😊

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

    Nice and concise, love the content -- keep it up!

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Great to hear, thanks 😊

  • @thanhatnguyen8137
    @thanhatnguyen8137 ปีที่แล้ว +4

    Thanks

  • @Danger-oe8jm
    @Danger-oe8jm ปีที่แล้ว +2

    Thanks for this very useful video

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Glad it was helpful 😊

  • @personalgamedevyt9830
    @personalgamedevyt9830 ปีที่แล้ว +2

    Thank you for this lesson. As others have said, this is a really useful way of using events!

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Glad you found it helpful 😊

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

    Amazing content thank you so much !

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Thanks for this comment 😊

  • @aarondelgado3421
    @aarondelgado3421 ปีที่แล้ว

    Great video! I already knew about Time.timeScale but it was good to learn about the Animation and Update tidbits.

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

    Thank you:)

  • @raelroque5595
    @raelroque5595 ปีที่แล้ว +4

    nice

  • @3DPActionFigures
    @3DPActionFigures ปีที่แล้ว +1

    Nice tuts!
    I hope next you do how to make the same character transfer between levels/maps/scenes like for example the character goes into a portal, the map will change to indicate that the character have traveled through the portal.

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

    your videos is always cool ..

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Thanks for your support 😊

  • @JacksonAcademy1
    @JacksonAcademy1 ปีที่แล้ว +14

    *Brackeys, watch out.*

  • @esnevip
    @esnevip ปีที่แล้ว

    The way you explain things is fantastic!
    Could you do a tutorial on flying?

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Thanks for this comment.
      We'll add flying and gliding to the list of potential future videos 😊

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

    How would you freeze a single character? ie with a freeze ray or ice spell?

  • @DwightPotvin
    @DwightPotvin ปีที่แล้ว

    This is probably a good simple way to do it for small scale projects, but more main stream ones. It's best to use a scriptable object that can be read from any script, and check within the scripts themselves. This provides full control. Wrap all your inputs with a bool check except for the pause input.

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Hi, thanks for suggesting an alternative solution. Do you use the scriptable object just to stop input and still use timescale zero to pause animations, tree sway etc?

    • @DwightPotvin
      @DwightPotvin ปีที่แล้ว

      @@KetraGames it all depends, using the SO to set the value allows for full control. It allows you to pause or unpause certain elements of state machines, you can use it to turn off processes in shaders that are not bound by time scale. And if you do want an unscaled object to be paused under very specific situations, you can do it that way too.
      you can go as far as making an enum into a scriptable object and development different paused states / levels. Each level creating a different amount of influence depending on the need.

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      @Dwight Potvin, thanks so much for this. Enhancing the solution with a Scriptable Object would definitely be beneficial

    • @DwightPotvin
      @DwightPotvin ปีที่แล้ว

      @@KetraGames In general, getting people more familiar with SO's, even if it's something as small as a pause value in a tutorial, will benefit them in the long run. Especially since Unity is pushing heavily for SO's to be their main form of serialization.

  • @PsychoStudiosOfficial
    @PsychoStudiosOfficial ปีที่แล้ว

    THANKYOU SOOO SOOO MUCH! I do have one question though, how would I unlock and show my curser when paused? again, thank you sooo muccchhhh!

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Hi, to unlock the cursor when paused write a script with a method that sets the cursor lockstate to none - Cursor.lockState = CursorLockMode.None.
      Then you can hook up the Unity event to call this method when the game is paused. You would also need to do the opposite when the game resumes.
      Hope that helps 😊

  • @weckar
    @weckar 10 หลายเดือนก่อน

    Not ideal if you're manipulating timescale for any other reason. But a lock and key system overcomes that.

  • @stevethepirate
    @stevethepirate 2 หลายเดือนก่อน

    would it be possible to make an IPausable interface that anything you want to be paused could be haulted in their update? or would a C# interface not allow you to make that check? just thinking about having to go through everything in the game that may want to have a pause feature, and my brain would probably forget some of them unless i planned in advance. Or maybe a base class? or are neither of those a possibility?

    • @KetraGames
      @KetraGames  2 หลายเดือนก่อน +1

      Hi, good idea. You could create an empty interface that you assign to all scripts you want to pause. Then you could disable any scripts with this interface to stop the update method being called. Hope that helps 😊

    • @stevethepirate
      @stevethepirate 2 หลายเดือนก่อน

      @@KetraGames awesome!! i had some strict coworkers that really pushed me on that stuff. it's encouraging to see that some of that stuck with me. do you get into inheritance some with unity, or does that conflict with unity's component based architecture?

    • @KetraGames
      @KetraGames  หลายเดือนก่อน +1

      @@stevethepirate Inheritance isn't something that I tend to use much, but it can work in Unity. I'd advise to use it sparingly though. I'm sure you know this, but it's generally better to favour composition over inheritance, which Unity's component based architecture is geared toward.

    • @stevethepirate
      @stevethepirate หลายเดือนก่อน

      @@KetraGames oh okay! did not know that it isn't usually a good idea in Unity! thank you!

  • @eliminator7ful
    @eliminator7ful ปีที่แล้ว

    I didn't follow all of the last 30 seconds or so of this video. Could you please concentrate a few videos on the interaction of the Unity timescale and physics system? kthxbye.

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Hi, to give a bit more detail, if you set the timescale to zero the FixedUpdate method will not be called on any of your Game Objects. It's unlikely that you would need FixedUpdate to be called when the game is paused so it should be fine, but if you did need to have FixedUpdate called when paused then you'd have to do a bit more work yourself. Instead of setting timescale to zero you'd need to subscribe to the paused event and pause movement, animations etc all yourself. I wouldn't recommend it unless you really need it 😊

  • @muzboz
    @muzboz ปีที่แล้ว

    Pausing and Unpausing can be surprisingly complex! This tutorial covers some of the basics well.
    You can also Pause your game without adjusting TimeScale at all, but you need a function that'll go through and more manually pause/disable aspects of all your objects!
    This can seem a bit over the top, but at the end of the day, you may need to.
    And the code used is similar to a lot of Save/Load functionality, which you'll also maybe need to do!
    I made a Pause / Unpause / Save / Load base game architecture project, with explanation videos, and a way to download the project here, if you're interested...
    th-cam.com/users/playlist?app=desktop&list=PLA2kYB0UP03AjXCgnZ4Wl35BDgq2bZzWZ
    Check out the final video in the playlist for the latest version of the project.

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Thanks for sharing your solution 😊

  • @yakanashe
    @yakanashe ปีที่แล้ว

    instead of if() and else() in the pause script, you can also use ":" and "?" to set Time.timeScale to 0 and 1 according to if _isPaused is true or false

    • @KetraGames
      @KetraGames  ปีที่แล้ว

      Thanks for sharing your tip 😊