Make sure to put isPaused = false; at the end of the GoToMainMenu function, so that you can enable inputs if you decide to click play in the main menu!
I copied the code to the T and I keep getting errors like 'Time' does not contain a definition for 'timescale'. 'PauseMenu.isPaused' cannot be used like a method. And Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement. WHAT DO I DO?
Tip: If your pause menu spams like a minigun when you press Escape, you can change the if (Input.GetKey(KeyCode.Escape)) to if (Input.GetKeyDown(KeyCode.Escape)).
thank you so much for sharing your videos with us, I feel like I honestly learn more from you than the coding courses I've been taking !! You're very good at what you do :)
Even though you had project of yours that has already been nearly completed, you've successfully shown my dumb ass how to solve this particular "problem". Thank you so much
i followed brackeys tutorial on the same topic and it wouldnt work for me! i tried this one and it worked perfectly! thank you so much! im new to programming and video game development and your video just helped me out alot... you just gained a sub
Hey, so idk if youll see this but , My problem is that when the game is up the text choices "resume , quit " etc are overlayed on the game and it wont disappeared . they do work when I hit esc and the paused title comes up but the choices never leave?
Perfect, thanks! I'm just starting with all this and being able to set the timescale was the piece of the puzzle I was missing. Until now I had been setting a bool for "canMove" to false and wrapping it around every single movement command on my character but I was wondering what I would do about enemies and other environmental objects. I knew I could always give them something similar, but then having to tie all that in to a player pressing a key seemed awfully excessive. This looks like a much better solution!
Now that I think about it, I guess this is also where you could add a feature like Rimworld has where you have multiple play speed buttons or special effects like time slowing when you get hit with a fatal blow. Really good to know!
Hi, I'm just wondering I don't have a game manager and I don't know where to put the script so it's not working could you please tell me how where to actually put the script if I don't have a game manager?
I just have a little probleme, when i click on "resume" the first time, the next time i open the pause menu, if i press space the pause menu closed, even if my "space" button don't serve any purpose, not a big deal, but i'm curious to know why
Hello there, I don't know why but my button to return to the menu works again but when I start the game again the assignment in On Click ( ) is lost, I don't understand, it worked once, and the second time I try to play it doesn't work Start?
"gameManager" usually refers to an empty object where you asign all your codes in the scene (not related to the character or that kind of specific features). It function is to be the object that you will always call to make a code function work, in this case, to change your scene depending on the button you´re pressing. Its depends on you to give it to a principal camera or to an empty object tho
Hey, great tutorial! I was wondering if there's a way to stop the Standard Assets FPS Controller from letting the player still move the camera around when the pause menu is up, haven't been able to figure it out myself. Thank you!
Doesn't work for me im getting and issue with assigning it to a game object The game is freezing when I hit esc but there is no menu popup Im trying to figure it out right now but there's an issue with setting the script to something, and then putting something as a the gameobject for pausemenu Edit - I believe it has something to do with the camera settings Edit 2 - Yes it was the canvas, once I set it to follow the camera it made my already small menu microscopic. So I saved a copy of the panel, made the change, then repasted the panel and it's perfect. Now my pause menu follows my camera screen which is what I wanted. You need to set the pausemenu as a gameobject in the pause menu script Edit 3 - You cannot call PauseMenu from another CS script it does not exist You have to import it
for those who have issue with UnassignedReferenceException error, go chack out "PAUSE MENU in Unity" by Brackeys, he did it in a slightly different way and it works
Thank you! But I have a question. The game that I'm making is for Android and for making the game in pause I have to click a button with a clicking function. I putted that but when I press the button the player jumps because of the function that is *if(Input.GetMouseButtonDown(0) && canJump)*. That is a disturbing thing because when I want to pause the game the player jumps. If you could help me I would be rrally grateful!
why my functions (pauseGame(), resumeGame()) are not appearing in inspector when on click() .. i have put the the script in separate gameobject and applied this game object in on click() .. still not functions of the script appearing, why?
how could i make a pause menu for a multiplayer fps game? because when I press escape, the cursor still moves my camera for whatever reason, even if I have an if else condition in place to prevent that
UnassignedReferenceException: The variable pauseMenu of PauseMenu has not been assigned. You probably need to assign the pauseMenu variable of the PauseMenu script in the inspector. PauseMenu.PausedGame () (at Assets/Scripts/PauseMenu.cs:35) PauseMenu.Update () (at Assets/Scripts/PauseMenu.cs:23)
Hi- I’m using SC_FPSController script and I can’t freeze the the camera moving with the mouse (so can’t stop player movement) Should I unconnected them so solve that??
I know this video is super old and no one cares, but is the audio from the beginning from Juice Universe? (I believe that's what it's called now after it got renamed)
ok but now how do i make it work... like i do make pressing the quit game button quit the game and make the resume game resume it when you click it or the back to menu take me to the main menu
for Standard first person controller assets store using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityStandardAssets.Characters.FirstPerson; public class PauseMenu : MonoBehaviour { public static bool GameIsPaused = false; public GameObject player; public GameObject pauseMenuUI; [Header("it hides your hud when you Pause")] // example | "E" to open door | public GameObject HUD; private void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { if (GameIsPaused) { Resume(); } else { Pause(); } } } public void Resume() { pauseMenuUI.SetActive(false); Time.timeScale = 1f; GameIsPaused = false; player.GetComponent().enabled = true; Cursor.visible = false; Cursor.lockState = CursorLockMode.Locked; HUD.SetActive(true); } public void Pause() { pauseMenuUI.SetActive(true); Time.timeScale = 0f; GameIsPaused = true; player.GetComponent().enabled = false; Cursor.visible = true; Cursor.lockState = CursorLockMode.None; HUD.SetActive(false); } public void LoadMenu() { Time.timeScale = 1f; SceneManager.LoadScene("MAINMENU"); GameIsPaused = false; player.GetComponent().enabled = false; Cursor.visible = true; Cursor.lockState = CursorLockMode.None; } public void QuitGame() { Debug.Log("Quitting game..."); Application.Quit(); } }
Someone help me please! is giving the error: "The name (Principal) is not in the context csharpCS0103". This code would be to change the scene, in this case it would be for the Main Menu scene, I changed the scene name to "Principal" but it will not go at all!
This is very late but the way to fix this (i think) is to 1.) Go to the top left 2.) Click on file 3.) Click on build settings 4.) Drag and drop all your scenes into the big space (make sure you drag them into the order you want people to see it in)
Hi, thanks for the video! To stop receiving inputs for the gamepad(it's moving the character even when paused) e still making it available to navigate the menu, how do I achieve that?
Hello, I followed the tutorial and I like it! but it seems there is a problem happening to me, when I pause the game my Standard FPS controller still rotating any advise?
Guys, please be careful about that method called GoToMainMenu(). Cause if you forget to add that "Time.timeScale = 1" line, your game is freezing and just buttons working. No animation or anything else...
Assets/scripts/PauseMenu.cs(50,43): error CS1002: ; expected if you get this error it’s a typo and you got carried away typing all that code and forgot to put a single ; at the end of your line.
@@whysl oh was this comment still here I forgot to delete I solved this problem 7 days ago but I’m still gonna leave it here just if anyone is an idiot like me and makes any typos.
unity gives me an error saying " PauseMenue does not have a definition for SetActive" on top of that the public gameObject does not appear in the scripts inspector. Can anyone help?
my main menu is stuck for some reason after going from the pause menu, what could be the problem ? i hope someone answers asap really need it for school
UnassignedReferenceException: The variable pauseMenu of PauseMenu has not been assigned. You probably need to assign the pauseMenu variable of the PauseMenu script in the inspector. PauseMenu.Start () (at Assets/Scripts/PauseMenu.cs:14) PauseMenu.ResumeGame() (at Assets/Scripts/PauseMenu.cs:42) what I miss or did wrong?
A "touch" registers as a mouse click. It can easily work with Mobile. Instead of pressing the Escape key you'd need some sort of Pause button on the screen
I've found the solution though! Go to Edit -> Project Settings->Player->Under Other Settings under Configuration is the option Active Input Handling. Select Both. Hope this helped!
I HAVE A PROBLEM Escape button do not work and i checked in the setting in the Input Manager to affect the name in the code as the name of the button in the settings... PLEASE HELP
unity has a defult setting that makes the escape key allow you to move your mouse outisde the game viewer to exit play mode, i set it to Q for me for testing purposes
I would change it to “…GetKeyDown(KeyCode.P)) “ For it to work as when playing a game you don’t really want to press “esc” as takes away from immersion
i'm with the following error Assets\scripts\PauseMenu.cs(45,9): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
Make sure to put isPaused = false; at the end of the GoToMainMenu function, so that you can enable inputs if you decide to click play in the main menu!
Thank you for this comment!
THANk YOU
I copied the code to the T and I keep getting errors like 'Time' does not contain a definition for 'timescale'. 'PauseMenu.isPaused' cannot be used like a method. And Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement. WHAT DO I DO?
@@austinschaefer804 idk
@@austinschaefer804 Are you still having trouble? If so, show me your script, I may be able to spot the issue, but I need the script.
Thanks for making it simple and to the point. I appreciate the lack of useless filler that most people go for
Thanks for the kind feedback!
having a youtuber that makes content on exactly what i need and in 2020 is godly. thanks!
your videos are super well made, beginner friendly, and perfect for game jams! please continue making tutorials!
That makes me really happy you think that, no plans to stop yet!
@@BMoDev I 100% agree with this guy, every question i've had in the past 24 hours your channel has answered in the most accessible way. Thank you!
Tip: If your pause menu spams like a minigun when you press Escape, you can change the if (Input.GetKey(KeyCode.Escape)) to if (Input.GetKeyDown(KeyCode.Escape)).
hahahah epic comment!
+i want to thank you for this gem! I have been trying for hours to fix it!
bro finna be honest THIS GUY SOUNDS AWESOME his voice is so calming and soothing. Never got a more awesome experience from coding thanks man.
Thats crazy to me, but I appreciate it 💙
thank you so much for sharing your videos with us, I feel like I honestly learn more from you than the coding courses I've been taking !! You're very good at what you do :)
these tutorials are so useful for my game development, keep up the great content
This really makes me happy to hear! Will do my best 🙏 I want more people bringing their ideas to life!
Even though you had project of yours that has already been nearly completed, you've successfully shown my dumb ass how to solve this particular "problem". Thank you so much
Tip: you actually cant put script everywhere u want (not on PauseMenu because script wont work if u disable gameobject :D)
Good advice, i had that problem n now i know how to solve it. Thanks
i followed brackeys tutorial on the same topic and it wouldnt work for me! i tried this one and it worked perfectly! thank you so much! im new to programming and video game development and your video just helped me out alot... you just gained a sub
Happy to hear it! Keep it up!
BMo thanks!
@@BMoDev for some reason the player is blocking the pause menu buttons from working
I wish all tutorials were like this you know very short direct to the point and entertaining.
Hey, so idk if youll see this but , My problem is that when the game is up the text choices "resume , quit " etc are overlayed on the game and it wont disappeared . they do work when I hit esc and the paused title comes up but the choices never leave?
Why the hell are you so underrated? These are some straight on point Tutorials man! Thanks
Make sure that you change isPaused bool to false in the Main menu function, otherwise your controls will be locked when you play again
thanks i'll trying all day to find out
Perfect, thanks! I'm just starting with all this and being able to set the timescale was the piece of the puzzle I was missing. Until now I had been setting a bool for "canMove" to false and wrapping it around every single movement command on my character but I was wondering what I would do about enemies and other environmental objects. I knew I could always give them something similar, but then having to tie all that in to a player pressing a key seemed awfully excessive. This looks like a much better solution!
Now that I think about it, I guess this is also where you could add a feature like Rimworld has where you have multiple play speed buttons or special effects like time slowing when you get hit with a fatal blow. Really good to know!
Hi, I'm just wondering I don't have a game manager and I don't know where to put the script so it's not working could you please tell me how where to actually put the script if I don't have a game manager?
This is perfect. Thank you for the efficient rundown!
Is "pauseMenu" the name of an existing object or is it assigned to the menu by the script?
Thanks for the tutorial ! It's very nice and I really needed that !!
Looking forward your next 5min videos !!
again, i search "Unity 2d pause menu" and the second video is this one, like the other, i'm not disappointed, i think i'm going to subscribe x)
I just have a little probleme, when i click on "resume" the first time, the next time i open the pause menu, if i press space the pause menu closed, even if my "space" button don't serve any purpose, not a big deal, but i'm curious to know why
Dude you are my new god, thank you so much :D
You're the Goat. Helped me out a ton.
You're a beautiful human being Mr.BMo.
And you can qui...
Im learning with your tutorials thanks a lot :)
Awesome, keep it up!
When I press escape pause menu doesn't show up any solution?🥺
Hello there,
I don't know why but my button to return to the menu works again but when I start the game again the assignment in On Click ( ) is lost, I don't understand, it worked once, and the second time I try to play it doesn't work Start?
5:48 what is my gameManager ? the Camara ?
"gameManager" usually refers to an empty object where you asign all your codes in the scene (not related to the character or that kind of specific features). It function is to be the object that you will always call to make a code function work, in this case, to change your scene depending on the button you´re pressing.
Its depends on you to give it to a principal camera or to an empty object tho
I've used your code to make a death screen, but when i die my mouse doesn't show up, do you know why this is?
Hey, great tutorial! I was wondering if there's a way to stop the Standard Assets FPS Controller from letting the player still move the camera around when the pause menu is up, haven't been able to figure it out myself. Thank you!
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
player.SetActive(false);
im using both youtube tutorials and chatgpt both help a lot. first i get what i want on youtube than expand with chatgpt, and im actually learning.
Doesn't work for me im getting and issue with assigning it to a game object
The game is freezing when I hit esc but there is no menu popup
Im trying to figure it out right now but there's an issue with setting the script to something, and then putting something as a the gameobject for pausemenu
Edit - I believe it has something to do with the camera settings
Edit 2 - Yes it was the canvas, once I set it to follow the camera it made my already small menu microscopic.
So I saved a copy of the panel, made the change, then repasted the panel and it's perfect. Now my pause menu follows my camera screen which is what I wanted.
You need to set the pausemenu as a gameobject in the pause menu script
Edit 3 - You cannot call PauseMenu from another CS script it does not exist
You have to import it
Thank you so much for this, you´re a life saver!
for those who have issue with UnassignedReferenceException error, go chack out "PAUSE MENU in Unity" by Brackeys, he did it in a slightly different way and it works
This helped me so much thank you kind stranger
'PauseMenu' does not contain a definition for 'isPaused'-error is popping up. how do i fix this?
very quick and to the point, I appreciate that :]
So I have a fade into scene ui in my project, and so now my buttons don’t press because of it. Anyway to fix this? Thanks
Thank you! But I have a question. The game that I'm making is for Android and for making the game in pause I have to click a button with a clicking function. I putted that but when I press the button the player jumps because of the function that is *if(Input.GetMouseButtonDown(0) && canJump)*.
That is a disturbing thing because when I want to pause the game the player jumps. If you could help me I would be rrally grateful!
When i go to "on click()" - button i dont have the options that u have
oh my god it works thanks!!
While this method is great for tiny games, hard setting the timescale will often lead to issues in larger games.
Amazing tutorial. Many thanks!!
I came across this video and it helped fix a bug in my pause menu so THANK YOU =>
Thank you!! Your videos are awesome
why my functions (pauseGame(), resumeGame()) are not appearing in inspector when on click() .. i have put the the script in separate gameobject and applied this game object in on click() .. still not functions of the script appearing, why?
ThankYou so much dude your vids been helping out a lot recenly
if i was making a 3D game how would i stop my camera from moving around when im in the menu
Smashed the like as hard as I could have
My man 🙏
*smash that like button two times!*
im using the same version as you and before you did the static ball and yeah in my 3d it doesnt work
how could i make a pause menu for a multiplayer fps game? because when I press escape, the cursor still moves my camera for whatever reason, even if I have an if else condition in place to prevent that
UnassignedReferenceException: The variable pauseMenu of PauseMenu has not been assigned.
You probably need to assign the pauseMenu variable of the PauseMenu script in the inspector.
PauseMenu.PausedGame () (at Assets/Scripts/PauseMenu.cs:35)
PauseMenu.Update () (at Assets/Scripts/PauseMenu.cs:23)
just assign the variable
How i can do this?
@@tobystohow?
Oh my god, it's been 3 fucking years, I was so dumb bro 😂
@@TBag-xl9qz google "how to assign a variable in C#" or in these days ask chatgpt
Awesome tutorial. I have a pause menu now.
Nice work!
Can you make a gameover menu thing couse i'm stuck with things like that
Sure, I'll add it to my backlog
thank you for this great video, plain and simple!
Hi- I’m using SC_FPSController script and I can’t freeze the the camera moving with the mouse (so can’t stop player movement)
Should I unconnected them so solve that??
Hi my script isnt working and would like help my script is making the buttons work
Thanks a lot, much appreciated
Thanks! Good video!
Helped so much! 👍
How do you fix it so it works after you have buildt and run the game? Only works in game tab in the editor but not in the buildt version
I know this video is super old and no one cares, but is the audio from the beginning from Juice Universe? (I believe that's what it's called now after it got renamed)
ok but now how do i make it work... like i do make pressing the quit game button quit the game and make the resume game resume it when you click it or the back to menu take me to the main menu
I'm using this for a VR game, however with this script i cannot interact with the buttons, without the script i can. Any ideas how to fix that?
for Standard first person controller assets store
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityStandardAssets.Characters.FirstPerson;
public class PauseMenu : MonoBehaviour
{
public static bool GameIsPaused = false;
public GameObject player;
public GameObject pauseMenuUI;
[Header("it hides your hud when you Pause")] // example | "E" to open door |
public GameObject HUD;
private void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (GameIsPaused)
{
Resume();
}
else
{
Pause();
}
}
}
public void Resume()
{
pauseMenuUI.SetActive(false);
Time.timeScale = 1f;
GameIsPaused = false;
player.GetComponent().enabled = true;
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
HUD.SetActive(true);
}
public void Pause()
{
pauseMenuUI.SetActive(true);
Time.timeScale = 0f;
GameIsPaused = true;
player.GetComponent().enabled = false;
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
HUD.SetActive(false);
}
public void LoadMenu()
{
Time.timeScale = 1f;
SceneManager.LoadScene("MAINMENU");
GameIsPaused = false;
player.GetComponent().enabled = false;
Cursor.visible = true;
Cursor.lockState = CursorLockMode.None;
}
public void QuitGame()
{
Debug.Log("Quitting game...");
Application.Quit();
}
}
Ty you are very cool :)
@@bob32423 np ;)
Someone help me please! is giving the error: "The name (Principal) is not in the context csharpCS0103".
This code would be to change the scene, in this case it would be for the Main Menu scene, I changed the scene name to "Principal" but it will not go at all!
That could be referring to the UI element.
That happend to Me too
Coz ist fake
This is very late but the way to fix this (i think) is to
1.) Go to the top left
2.) Click on file
3.) Click on build settings
4.) Drag and drop all your scenes into the big space (make sure you drag them into the order you want people to see it in)
i love your videos
Hi, thanks for the video!
To stop receiving inputs for the gamepad(it's moving the character even when paused) e still making it available to navigate the menu, how do I achieve that?
Very helpful! thanks
Ty so much, you helped me a lot!!
i got the menu button and quit button to work but i cant resume the game or push escape to take the menu away
Hello, I followed the tutorial and I like it! but it seems there is a problem happening to me, when I pause the game my Standard FPS controller still rotating any advise?
Guys, please be careful about that method called GoToMainMenu(). Cause if you forget to add that "Time.timeScale = 1" line, your game is freezing and just buttons working. No animation or anything else...
Hmm I'm pressing the button but the menu does not come up. I already added the gameobject to the script as well. Can anyone help?
can you put the script in comments/description?
Assets/scripts/PauseMenu.cs(50,43): error CS1002: ; expected
if you get this error it’s a typo and you got carried away typing all that code and forgot to put a single ; at the end of your line.
just put the ";" symbol in 50 line
@@whysl oh was this comment still here I forgot to delete I solved this problem 7 days ago but I’m still gonna leave it here just if anyone is an idiot like me and makes any typos.
unity gives me an error saying " PauseMenue does not have a definition for SetActive" on top of that the public gameObject does not appear in the scripts inspector. Can anyone help?
Great video thx : )
For some reason my buttons aren't working at all, can't click or hover on them. Any possible causes?
You might not have an EventSystem?
Thanks that's help me a lot
I don't have anything like GameManager... What gameObject should I put into "On click" event instead?
canvas
you put the scirpt in the canvas
I dont know where you put the script, becasue you said it doesnt matter where the script lives but it clearly does as its not working for me
What kind of error you getting? Whys it not working?
my main menu is stuck for some reason after going from the pause menu, what could be the problem ?
i hope someone answers asap really need it for school
UnassignedReferenceException: The variable pauseMenu of PauseMenu has not been assigned.
You probably need to assign the pauseMenu variable of the PauseMenu script in the inspector.
PauseMenu.Start () (at Assets/Scripts/PauseMenu.cs:14)
PauseMenu.ResumeGame() (at Assets/Scripts/PauseMenu.cs:42)
what I miss or did wrong?
I have the same problem and I can't figure it out
Same here
Same
is this working with touches ??
i want to make it for my android mobile game?
A "touch" registers as a mouse click. It can easily work with Mobile. Instead of pressing the Escape key you'd need some sort of Pause button on the screen
@@BMoDev a pause button connected with the menu , thanks
i don't have a PauseMenu function. can someone explain why? thanks in advance.
bro how to off al sounds when the game is pused
Great tutorial, but this doesn't work with unity's new input system.
I'm dealing with the same issue right now.
I've found the solution though!
Go to Edit -> Project Settings->Player->Under Other Settings under Configuration is the option Active Input Handling. Select Both.
Hope this helped!
@@baron_shiro9877 It does, thanks, but I think I might stick with the old input system as there are more supported assets/scripts for it
@@baron_shiro9877 Thank you!
Time.timeScale, affects button animations, how to avoid it?
when i try to click a button my cursor disables and goes into the game
Your game locks your mouse so you have to make it unlock when it's paused and relock when resumed
@@a26lolhart thanks for replying 8 months later
when i press play the game goes on but when i press the esc button it will not show up. can someone help me?
What if you have animations and want to use them? Example you have options button and want to make it slide in the option screen if you click on it.
sail to Ukraine🙂
I HAVE A PROBLEM
Escape button do not work and i checked in the setting in the Input Manager to affect the name in the code as the name of the button in the settings...
PLEASE HELP
unity has a defult setting that makes the escape key allow you to move your mouse outisde the game viewer to exit play mode, i set it to Q for me for testing purposes
I would change it to “…GetKeyDown(KeyCode.P)) “
For it to work as when playing a game you don’t really want to press “esc” as takes away from immersion
This is perfect but when I pause the game, I can still move my character even when paused and in pause menu. How to prevent this?
look into pausing time in unity
Time.timeScale doesn't seem to work on my Unity.
Edit: For that matter, neither does triggering the paused bool.
try looking through the package manager sry if im to late
i'm with the following error
Assets\scripts\PauseMenu.cs(45,9): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
That's a syntax error. Please share your code, we have a channel in our discord to help with these issues! (Should be a quick fix)
thanks you guy
How can I make the escape button android friendly?
finished the PauseMenu script. error The Name 'PauseGame' does not exist in the current context. pls help?!
Check to see if your PauseGame() function has a typo
What vs code extensions do u use for unity