Тёмный

Pausing your Game and Adding a Menu - Unity Tutorial 

samyam
Подписаться 86 тыс.
Просмотров 15 тыс.
50% 1

How to pause game movement and input, make a menu, and add an animation while the game is paused.
ᐅGet the full Source Code Bundle to my Unity Tutorials 🤓
sam-yam.itch.i...
📥 Get the Source Code 📥
/ pause-game-code-38928648
🤝 Support Me 🤝
Patreon: / samyg
Donate: ko-fi.com/samyam
Disclosure: This post may contain affiliate links, which means we may receive a commission if you click a link and purchase something that we have recommended. While clicking these links won't cost you any money, they will help me fund my development projects while recommending great assets!
😎 Cool Unity Assets 😎
ᐅPeek - Editor Toolkit: assetstore.uni...
ᐅEditor Console Pro: assetstore.uni...
ᐅRainbow Folders 2: assetstore.uni...
💖💖THANK YOU TO ALL MY PATRONS 💖💖
❯❯❯ My Links ❮❮❮
💗 Patreon 💗
/ samyg
💬 Discord Server 💬
/ discord
🐦 Twitter 🐦
/ samyam_utube
📚 Facebook 📚
/ samyam.youtube
🎵 Music 🎵
Fretless by Kevin MacLeod
Link: incompetech.fi...
License: creativecommons...
👍 Like and Subscribe! 👍
🖥️ Computer Setup 🖥️
*As an Amazon Associate I earn from qualifying purchases.
www.amazon.com...
#unity3d #unitytutorial #unity2021

Опубликовано:

 

14 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 66   
@MarcusSanatan
@MarcusSanatan 3 года назад
This was great! So many resources don't utilize the new input system - your tutorials are really filling that gap. Keep up the great work!
@samyam
@samyam 3 года назад
Thank you!!
@jameswilson820
@jameswilson820 Год назад
I was struggling trying to pause with the new input system, until I found your tutorial! Thank you!!!
@My_Lyfe
@My_Lyfe 2 года назад
Insanely helpful, this is literally the only channel I ever go to for new unity input system advice, you're legendary thank you so much!!!
@Xxnightwalk1
@Xxnightwalk1 2 года назад
This is exactly what I was looking for. Very clear, using the new Input system, just what I needed I will consider you to be the new Brackeys :)
@samyam
@samyam 2 года назад
New Sam! 😉 Thanks!
@embersandashes
@embersandashes 2 года назад
Been having issues that I couldn't figure out, but after watching, I finally got the menu to work! Thanks for the help!
@icoso
@icoso 2 года назад
Exactly what I needed - thank you so much! Even after two years, this tutorial is incredibly helpful and I got everything working with no problems :D Keep up the awesome work, Samyam! You're singlehandedly saving my game dev journey :P
@samyam
@samyam 2 года назад
Thank you so much Icoso! Such nice words 😊
@jhonnyjoestar1220
@jhonnyjoestar1220 4 года назад
You are the only channel that use and show the right documentation.
@AlexM-xj7qd
@AlexM-xj7qd 3 года назад
Your videos get few views in comparison to others youtubers but don't stop making them. These videos are amazing and super helpful!
@samyam
@samyam 3 года назад
Thank you so much!! Well, I think I’ve grown at a good rate, I started over a year ago and I’m already almost at 10K subs!
@MakhnoAndrii
@MakhnoAndrii Год назад
Very useful video. I only want to add if someone like me using input system in ThirdPersonAsset, you need to add two methods in StarterAsset (similar to Jump) and do almost the same as video except you need to change a property of menu in StarterAsset to false in current c# script.
@Kaoji
@Kaoji 4 года назад
Such great videos! Your explanations help me understand the program better, such great exercises.
@samyam
@samyam 4 года назад
Thanks!
@gamedevbaiyi936
@gamedevbaiyi936 2 года назад
Awesome. Thank you samyam. I learned something new. 😁
@samyam
@samyam 2 года назад
Yay! 🤘
@1984ordep
@1984ordep 7 месяцев назад
awesome vid! How would you trigger the menu from a button on a gamepad lets stay the "START"button?
@starsquad9814
@starsquad9814 3 года назад
Thank you so much for teaching me how buttons work with the new input system. It really saved me thank you.
@REOsama
@REOsama 2 года назад
You are a literal life saver, thank you so much!
@mcleverm01
@mcleverm01 2 года назад
Thanks Sam! Really helped!
@dhymers
@dhymers 2 года назад
Something missing from this which is useful, if you are using the new input system, make sure it is set to process inputs in dynamic update in project settings>input system and not fixed update, I tried a second method (this method is better because it really splits the input system open which helped me a lot.) before I realized the input system was not processing inputs when paused. (fixedUpdate isn't called when timescale = 0) Great vid otherwise !! thankyou.
@samyam
@samyam 2 года назад
Thanks for pointing this out!!
@IcyBonesTV
@IcyBonesTV Год назад
This comment saved my life. Thank you
@fonta22
@fonta22 3 года назад
Really great tutorial! thanks for doing it!
@kj.junaid
@kj.junaid 2 года назад
Great tutorial videos always.
@trashcaster
@trashcaster 11 месяцев назад
Has anyone figured out a good way to implement a per-player pause? Like the whole game becomes paused, but only 1 player gets access to the pause menu (the one who paused it)? I'm wanting to add a menu that allows you to adjust your character's colors/parts and I can't seem to figure out a good way to implement this cleanly. I've seen examples where the input devices of other players become disabled during this "pause" for the menu so that they can't fight with the inputs, but it's really not elegant. Another option I would be willing to explore is being able to have a shared pause, but then have an option to have a floating menu above the players. What's the best way to create a floating menu that takes the inputs while open versus the player movement taking the inputs? Just a boolean or nullable reference that will indicate whether the player has their menu open, and just ignore the input values for the movement while the menu is up (and vice versa for when the menu is not up)?
@Bedo1012
@Bedo1012 2 года назад
Great Work!
@samyam
@samyam 2 года назад
Thanks!
@big4gamestudio868
@big4gamestudio868 3 года назад
Exactly what I needed, thanks! Great content!
@hasmanking
@hasmanking 2 года назад
i dont know why but when ever i press the pause button again after it has paused it wont work?
@galberger3937
@galberger3937 Год назад
Hi. I did you codes and i have a problem with PuaseActive. It says that it could not be found. How to fix it?
@samyam
@samyam Год назад
PauseActive? Seems you misspelled it
@JKczolg
@JKczolg 3 года назад
hey, could you make a tutorial about pause menu button but with the "Player Input" components on 2 different game objects (as in u have your player inputs (movement etc.) and u have like a ui manager with another Player Input component with different input asset). or just how to do it with Player Input component. Thanks in advance.
@samyam
@samyam 3 года назад
It would be similar to how we do it in this video, for any one of the players if they press the pause button on their controller/keyboard then put the Time.timeScale to 0. So you can have a function in your player controller that gets called when the user pressed the pause action and sets the time scale.
@JKczolg
@JKczolg 3 года назад
@@samyam yea but you can have only 1 "Player input" per Player and if u add Another one on Another gameobj then only 1 will work(at least that whathappens with me). So yea, i was just hoping that it could be done more cleanly than to just subscribe pauseMenu() to the Escape btn :/
@JKczolg
@JKczolg 3 года назад
i.. em, looked at the warrior example project and i guess i know how it sohuld be done, kinda. I wanted to do it a bit differently but i guess this is ok too
@dontaewilliams9161
@dontaewilliams9161 4 года назад
Hello, this really helped me a lot. I also need some more help hehe, I'm very new at unity, like fresh off the boat. I was wondering is there a way to implement voice commands into unity for my game I'm trying to create? Essentially, I want a person playing the game to have to use a mic. So when the player says for example "sword" a sword then materializes into the player's hand after stating the proper voice command. The game is aimed towards a steam/ps4/xbox release may be mobile. thanks in advance.
@samyam
@samyam 4 года назад
Hey! Here's an awesome video from DapperDino showcasing simple Voice Recognition ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-29vyEOgsW8s.html And here are the docs: docs.microsoft.com/en-us/windows/mixed-reality/voice-input-in-unity
@Tomatech
@Tomatech 3 года назад
whats the benefit of having two input action assets with one action map each vs one action asset with two maps?
@samyam
@samyam 3 года назад
Well it depends on your use case and how you want to organize it. For example if you have two different action assets you will need to instantiate both, or have a PlayerInput component for each one (or you can swap the current action asset in the PlayerInput component for the new one). However if you have only one action asset you would only need to instantiate it once and can more easily get a reference to the action map you need. I'd say have an action asset for one use case, such as one for the player controls, and each map in that asset can correspond to controls for different situations, for example the player may have different controls for walking vs driving a boat (two different action maps). I'd also put the UI action map in the same as your main player controls asset since the PlayerInput component complains if you don't (if you want to synchronize the playerinput actions to the ui). It's up to you :)
@florider_hd
@florider_hd 3 года назад
wow. ive switched to new input system and now everything is fucked up and i cant switch back to the original (if i do it still doesnt work)
@samyam
@samyam 3 года назад
Sorry to hear that! I recommend backing up your project before you switch, try selecting Both under the Player Settings>Active Player Input Handling and see if that helps/reduces the number of errors. Then once the errors are resolved you can continue the switch.
@everluck9972
@everluck9972 2 года назад
(i had this issue which is why im responding to it a year later). All u gotta do is uninstall that in the package manager then go to Edit>Project Settings> Player > Open other settings and scroll down until you see "Active Input Handling" and switch it to the old system. Maybe u can get that old project back. Another issue could be all the coding u did using the old system. It may be easier to switch it in the code if u know how to cause that was one of my errors but I already had a working menu but wanted that bubble effect that samyam had so I came to this video.
@Kairinkai
@Kairinkai 3 года назад
Why does my input system not work
@samyam
@samyam 3 года назад
answered in discord ;)
@psymanic9657
@psymanic9657 3 года назад
So this works exactly once. and then never again. I can pause, unpause once I start the game one single time and that's it. any help at all?
@samyam
@samyam 3 года назад
Make sure the Pause function is getting called the second time (debug log), maybe a reference was destroyed?
@psymanic9657
@psymanic9657 3 года назад
@@samyamYeah I was a huge dummy and didnt call it the second time
@samyam
@samyam 3 года назад
That’s okay!
@kasquez
@kasquez 4 года назад
How can you make a time stop effect, like when everything stops, except the player? 👀
@samyam
@samyam 4 года назад
kasquez While the time is stopped (time.timescale), switch the movement * time.deltatime to movement * time.unscaleddeltatime
@samyam
@samyam 4 года назад
However if you want to Pause while a time stop effect is in place, then in the player script return out of the update function like I showed in the video to prevent movement
@kasquez
@kasquez 4 года назад
@@samyam Is almost what I had in mind. I'm gonna try that. Thanks for the reply :)
@samyam
@samyam 4 года назад
Of course! Feel free to join my discord if you have any more questions discord.gg/B9bjMxj
@Kairinkai
@Kairinkai 3 года назад
It doesnt let me put my PauseManager in my empty object
@samyam
@samyam 3 года назад
That’s probably because there’s an error on the script, check the console Window>General>Console
@Kenji_195
@Kenji_195 Год назад
With this I came to realize I can't just have every single control mapping in one single Input Actions script
@melomelomaniac
@melomelomaniac 3 года назад
hey, i'm really new to this and i followed the tutorial the best i could but i keep getting an error. it says The name 'paused' does not exist in the current context. any help? thanks
@samyam
@samyam 3 года назад
That means you didn’t declare the variable paused in your class. should look something like: private bool paused;
@melomelomaniac
@melomelomaniac 3 года назад
@@samyam i forgot to edit the comment earlier but i found the solution!! thank you a lot though :))
@CCLawhon
@CCLawhon Год назад
@@samyam at 5:28 for a fraction of a second the script is scrolled back to the top and we can see where you added the public bool paused = false; So, I'm curious, is it public or private? why??
@samyam
@samyam Год назад
@@CCLawhon It can be either really (depends on your use case - you can make it have a private setter and a public getter (this is a bit more advanced though)), I tend to keep things private so other scripts can't access them if they don't need to be accessed (helps prevent unnecessary bugs). However, in the code for the video I had it like this `public static bool paused = false;` which means any other script can access this variable even without a direct reference to the gameobject containing the script (hence the 'static'), so you could do PauseManager.paused from any other script to get the paused status. Hope that helps :)
@philipatha
@philipatha 4 года назад
What the hell is a 'buddin'?
@samyam
@samyam 4 года назад
🔳 Button
@CCLawhon
@CCLawhon Год назад
So mine wouldn't recognize "PauseAction"...I think it is because I had other Actions in my Action Map, so my script had to be PauseActions action; (note the s on the end of Action). Then in void Start mine says action.PauseGame.performed (I didn't need "Pause" before it since I already defined that's the Action Map I'm using by saying "Pause Actions" at the top). I think. This was the only way the code threw no errors--until game started. Basically, my key press for the menu causes nothing to happen. I used the Pause Manager with a Menu Button that I placed in my Game as a GameObject. When, on that menu button's On Click event, I refer to the PauseManager script and choose action of "game pause" it opens my menu and pauses the game. So the pause part works and the open menu part works...it's something with the key bind in the Action Map...I did it just like the video says, but I added "Pause" after my CharacterControls and UI Action Maps. Inside Pause is one Action, PauseGame which is bound to a key as "button." Thoughts? I still get this error, even though it is working via a menu button in game: NullReferenceException: Object reference not set to an instance of an object PauseManager.Start () (at Assets/PauseManager.cs:29) The code on my 29 is: action.PauseGame.performed += _ => DeterminePause(); And this error: NullReferenceException: Object reference not set to an instance of an object PlayerInput+PauseActions.Disable () (at Assets/PlayerInput.cs:1373) PauseManager.OnDisable () (at Assets/PauseManager.cs:24) The code on my 24 is: action.Disable(); ( replied with allll the other errors but they refer to Input Manager generated script the lines about enable/disable. Also, if you're getting "paused" not recognized error, look in video at 7:09 to add the correct bool so it recognizes the "paused" bool.
Далее
PAUSE MENU in Unity
12:13
Просмотров 989 тыс.
How to do pause in unity3D
8:55
Просмотров 18 тыс.
PUBG Mobile СТАЛ ПЛАТНЫМ! 😳
00:31
Просмотров 108 тыс.
choosing a game engine is easy, actually
15:08
Просмотров 527 тыс.
The right way to pause a game in Unity
9:09
Просмотров 60 тыс.
How to make a HEALTH BAR in Unity!
21:06
Просмотров 1,1 млн
6 Minute PAUSE MENU Unity Tutorial
6:09
Просмотров 117 тыс.
The Power of Scriptable Objects as Middle-Men
17:41
Просмотров 127 тыс.
How to Start Making Games with No Experience
10:55
Просмотров 109 тыс.