Oh yeah, I must've forgotten to add that but it's simple to do! In the script, on void Stop and void Play, you can just add Cursor.visible below the rest accordingly. So in void Stop() below Paused = true; you can add: Cursor.visible = true; And in void Play() below Paused = false; you can add Cursor.visible = false; Hope this helps too!
(for me) working code of the script: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class PauseMenu : MonoBehaviour { public static bool paused = false; public GameObject PauseMenuCanvas; // Start is called before the first frame update void Start() { Time.timeScale = 1f; } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { if (paused) { Play(); } else { Stop(); } } } void Stop() { PauseMenuCanvas.SetActive(true); Time.timeScale = 0f; paused = true; } void Play() { PauseMenuCanvas.SetActive(false); Time.timeScale = 1f; paused = false; } void MainMenuButton() { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1); } }
if ur mouse is locked or something and the press of the buttons doenst do anything try this: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class PauseMenu : MonoBehaviour { public static bool paused = false; public GameObject PauseMenuCanvas; // Start is called before the first frame update void Start() { Time.timeScale = 1f; } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { if (paused) { Play(); } else { Stop(); } } } void Stop() { PauseMenuCanvas.SetActive(true); Time.timeScale = 0f; paused = true; Cursor.lockState = CursorLockMode.None; } public void Play() { PauseMenuCanvas.SetActive(false); Time.timeScale = 1f; paused = false; Cursor.lockState = CursorLockMode.Locked; } void MainMenuButton() { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1); } }
use this using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class PauseMenu : MonoBehaviour { public static bool paused = false; public GameObject PauseMenuCanvas; // Start is called before the first frame update void Start() { Time.timeScale = 1f; } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { if (paused) { Play(); } else { Stop(); } } } public void Stop() { PauseMenuCanvas.SetActive(true); Time.timeScale = 0f; paused = true; Cursor.lockState = CursorLockMode.None; } public void Play() { PauseMenuCanvas.SetActive(false); Time.timeScale = 1f; paused = false; Cursor.lockState = CursorLockMode.Locked; } public void MainMenuButton() { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1); } }
I had 2 problems. 1. I didnt get the cursor working right in the pause menu 2. I could move with my charachter while pause menu. I got solutiones both of them. First one is simple addition in the code but the second one you have to use your own playermovement script name in the code instead of my "FPSController". This code is working for me: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class PauseMenu : MonoBehaviour { public static bool paused = false; public GameObject PauseMenuCanvas; // Start is called before the first frame update void Start() { Time.timeScale = 1f; Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { if (paused) { Play(); } else { Stop(); } } } void Stop() { if (!paused) { PauseMenuCanvas.SetActive(true); Time.timeScale = 0f; paused = true; Cursor.lockState = CursorLockMode.None; Cursor.visible = true;
@@garrettdeveloper Thanks I did resolve that problem but now i have another one, when i am in the pause menu everthing pauses exepect the camera i can still move the camera around does it have to do with the pause menu or just the personcontroller?
Hey, I'm having an issue where when I left or right click (I have grapple hooks in the game so you would normally swing) It puts the mouse in the game and you need to press escape again to get the mouse back but it doesn't let me click the options. Is there any way to resolve this issue?
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class PauseMenuScript : MonoBehaviour { public static bool Paused = false; public GameObject PauseMenuCanvas; // Start is called before the first frame update void Start() { Time.timeScale = 1f; } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { if (Paused) { Play(); } else { Stop(); } } } void Stop() { PauseMenuCanvas.SetActive(true); Time.timeScale = 0f; Paused = true; Cursor.visible = true; } void Play() { PauseMenuCanvas.SetActive(false); Time.timeScale = 1f; Paused = false; Cursor.visible = false; } public void MainMenuButton() { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1); } } - use this code bro!
Hello, that's a great idea. I've been wanting to make some more tutorials and I'm glad people like them! This is the first suggestion for a tutorial I've gotten so I'll put it on a list, thanks!
For people who face this issue in the future, double check u spelled everything right in the script. It basically says "when esc is pressed, enable this ui object". Remember caps sensitivity too. Ever since i spent 10mins tryna figure out why my "GetComponont" wasnt working im hawkeyeing these spellings
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class PauseMenu : MonoBehaviour { public static bool paused = false; public GameObject PauseMenuCanvas; // Start is called before the first frame update void Start() { Time.timeScale = 1f; } // Update is called once per frame void Update() { if (input.Getkeydown(KeyCode.Escape)) { if(paused) { Play(); } else { Stop(); } }
When i got to main menu through the pause menu, it says "no cameras rendering" and the menu stops working. I have a player with a camera in the game scene, and no cameras in the main menu scene, how do i fix it?
how do i fix the error where it says "You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings"?
so I remember your fix oculus vids I need help with mine so whenever I log on to my oculus it seems normal but the home page/store it automatically y scrolls down when I play a game my character moves backwards automatically how do you fix this?
Sounds like your oculus controller is stuck srolling down or holding a key down, you could try taking the battery out and restarting it, or try another controller!
the cursor lock dsnt work when I click on resume or options or quit the mouse disappears and i cant prerss on the buutoms but if i die in my game then my game over ui pop up and then i can press on the play options quit button so thats mean i have to everything right just i need in my script something for the cursor i think using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class PauseMenu : MonoBehaviour { public static bool Paused = false; public GameObject PauseMenuCanvas; // Start is called before the first frame update void Start() { Time.timeScale = 1f; PauseMenuCanvas.SetActive(false); } // Update is called once per frame void Update() { if(Input.GetKeyDown(KeyCode.Escape)) { if(Paused) { Play(); } else { Stop(); } } } void Stop() { PauseMenuCanvas.SetActive(true); Time.timeScale = 0f; Paused = true; Cursor.visible = true; } public void Play() { PauseMenuCanvas.SetActive(false); Time.timeScale = 1f; Paused = false; Cursor.visible = false; } public void MainMenuButton() { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1); } }
i know im 6 months late, but i have a script that i did make with chatgpt because im not good at C# but it makes it so whenever you press esc it makes it so you can move it wherever you want and when you press it again, it locks the mouse again here it is: using UnityEngine; public class MouseToggle : MonoBehaviour { private bool isCursorLocked = true; private void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { isCursorLocked = !isCursorLocked; if (isCursorLocked) { StartCoroutine(ToggleCursorLock()); } else { StopCoroutine(ToggleCursorLock()); Cursor.lockState = CursorLockMode.None; Cursor.visible = true; } } } private System.Collections.IEnumerator ToggleCursorLock() { while (true) { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; yield return new WaitForSeconds(0.1f); // Adjust the delay as needed Cursor.lockState = CursorLockMode.None; Cursor.visible = true; yield return new WaitForSeconds(0.1f); // Adjust the delay as needed } } private void Start() { // Start with the cursor locked Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } }
Hi! It has to do with how you place the buttons and layers. Try placing the buttons on the same canvas/panel as the pause menu and make it all under one canvas
Hey I have been running into a problem, I have managed to follow every step. Everything works except for when I click the "Main Menu" button on the pause screen, I go back to the main menu but I cannot click anything.
using System.Collections; using System.Collections.Generic; using UnityEngine; public class MouseUnlock : MonoBehaviour { // Start is called before the first frame update void Start() { UnlockMouse(); } // Update is called once per frame void Update() {
Hi, I don't think you'd want your pause menu options to be another Unity scene, because you'd need to use Scene management.loadScene and when you go back into the game scene everything would restart. I would suggest taking the features of your options menu and adding them into your in-game main menu
That means at the end of your statements, you need to add a semicolon. So add ; to the end of your statements, you can also see where they go in the video!
It means you haven't defined what the name "Paused is", in this case it is a boolean. In my script on line 8, I defined Paused as "public static bool Paused = false" so that we can set the Paused function with the script. Hope this helps!
my code isnt working i dont know why if its something stupid i only just started coding using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class NewBehaviourScript : MonoBehaviour { public static bool paused = false; public GameObject PauseMenucanvas; // Start is called before the first frame update void Start() { Time.timeScale = 1f; } // Update is called once per frame void Update() { if (input.Getkeydown(KeyCode.Escape)) { if(paused) { Play(); } else { Stop(); } }
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class PauseMenu : MonoBehaviour { public static bool paused = false; public GameObject PauseMenuCanvas; // Start is called before the first frame update void Start() { Time.timeScale = 1f; } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { if (paused) { Play(); } else { Stop(); } } } void Stop() { PauseMenuCanvas.SetActive(true); Time.timeScale = 0f; paused = true; } public void Play() { PauseMenuCanvas.SetActive(false); Time.timeScale = 1f; paused = false; } public void MainMenuButton() { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1); } }
Does this work with locked mouse as well?
Oh yeah, I must've forgotten to add that but it's simple to do! In the script, on void Stop and void Play, you can just add Cursor.visible below the rest accordingly. So in void Stop() below Paused = true; you can add:
Cursor.visible = true;
And in void Play() below Paused = false; you can add
Cursor.visible = false;
Hope this helps too!
@@garrettdeveloper I had the same problem but I get error CS0103 do you know what might be the problem
@@garrettdeveloper bro I litterly switched to ue5 because I couldn’t figure this out 💀💀
@Middle school Developers ue5 is great! I've messed around with it but am too used to Unity. Hope it works out better for you ;)
@@garrettdeveloper it does, Thankyou!
this was amazing thanks man got given the task of making a pause menu for my group project and this was so easy to follow
No problem I'm glad it could help :)
Its Working Thank You
(for me) working code of the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PauseMenu : MonoBehaviour
{
public static bool paused = false;
public GameObject PauseMenuCanvas;
// Start is called before the first frame update
void Start()
{
Time.timeScale = 1f;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (paused)
{
Play();
}
else
{
Stop();
}
}
}
void Stop()
{
PauseMenuCanvas.SetActive(true);
Time.timeScale = 0f;
paused = true;
}
void Play()
{
PauseMenuCanvas.SetActive(false);
Time.timeScale = 1f;
paused = false;
}
void MainMenuButton()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
}
}
if ur mouse is locked or something and the press of the buttons doenst do anything try this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PauseMenu : MonoBehaviour
{
public static bool paused = false;
public GameObject PauseMenuCanvas;
// Start is called before the first frame update
void Start()
{
Time.timeScale = 1f;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (paused)
{
Play();
}
else
{
Stop();
}
}
}
void Stop()
{
PauseMenuCanvas.SetActive(true);
Time.timeScale = 0f;
paused = true;
Cursor.lockState = CursorLockMode.None;
}
public void Play()
{
PauseMenuCanvas.SetActive(false);
Time.timeScale = 1f;
paused = false;
Cursor.lockState = CursorLockMode.Locked;
}
void MainMenuButton()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
}
}
everything works except that the game isnt frozen
wheres the mainmenu in the on click? i cant find it
@@Tarqx i cant find it either and i wasnt able to do that my self i just copied it
use this using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PauseMenu : MonoBehaviour
{
public static bool paused = false;
public GameObject PauseMenuCanvas;
// Start is called before the first frame update
void Start()
{
Time.timeScale = 1f;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (paused)
{
Play();
}
else
{
Stop();
}
}
}
public void Stop()
{
PauseMenuCanvas.SetActive(true);
Time.timeScale = 0f;
paused = true;
Cursor.lockState = CursorLockMode.None;
}
public void Play()
{
PauseMenuCanvas.SetActive(false);
Time.timeScale = 1f;
paused = false;
Cursor.lockState = CursorLockMode.Locked;
}
public void MainMenuButton()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
}
}
Awesome tutorial, thank you! :D
I'm glad it helped, that makes my day!
hello i need some help
i have it to where my camera moves while paused and cursor is locked.
how do i fix this?
my basement children are going to love this!
Nice
most goated tut thank u :p
yw :) I'll be making more!
I had 2 problems. 1. I didnt get the cursor working right in the pause menu 2. I could move with my charachter while pause menu. I got solutiones both of them. First one is simple addition in the code but the second one you have to use your own playermovement script name in the code instead of my "FPSController". This code is working for me:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PauseMenu : MonoBehaviour
{
public static bool paused = false;
public GameObject PauseMenuCanvas;
// Start is called before the first frame update
void Start()
{
Time.timeScale = 1f;
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (paused)
{
Play();
}
else
{
Stop();
}
}
}
void Stop()
{
if (!paused)
{
PauseMenuCanvas.SetActive(true);
Time.timeScale = 0f;
paused = true;
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
FPSController fpsController = FindObjectOfType();
if (fpsController != null)
{
fpsController.canMove = false;
}
}
}
public void Play()
{
if (paused)
{
PauseMenuCanvas.SetActive(false);
Time.timeScale = 1f;
paused = false;
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
FPSController fpsController = FindObjectOfType();
if (fpsController != null)
{
fpsController.canMove = true;
}
}
}
public void MainMenuButton()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
}
}
Could you tell me why it tells me FPSController.canMove is inaccessible due to its level of protection ?
what i need to do if i have 2 canvas?
For some reason when I click the buttons the mouse curser disappears... but the escape button works and pauses time correctly... hmmmm
Nice tutorial everything works fine but when i click options and then click back it dosent let me open the pause menu again.
Can you help me?
Hi, go back and make sure you followed setting up the buttons properly, like the onclick events, those are what makes the screens change :)
@@garrettdeveloper Thanks I did resolve that problem but now i have another one, when i am in the pause menu everthing pauses exepect the camera i can still move the camera around does it have to do with the pause menu or just the personcontroller?
Hey, I'm having an issue where when I left or right click (I have grapple hooks in the game so you would normally swing) It puts the mouse in the game and you need to press escape again to get the mouse back but it doesn't let me click the options. Is there any way to resolve this issue?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PauseMenuScript : MonoBehaviour
{
public static bool Paused = false;
public GameObject PauseMenuCanvas;
// Start is called before the first frame update
void Start()
{
Time.timeScale = 1f;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (Paused)
{
Play();
}
else
{
Stop();
}
}
}
void Stop()
{
PauseMenuCanvas.SetActive(true);
Time.timeScale = 0f;
Paused = true;
Cursor.visible = true;
}
void Play()
{
PauseMenuCanvas.SetActive(false);
Time.timeScale = 1f;
Paused = false;
Cursor.visible = false;
}
public void MainMenuButton()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
}
} - use this code bro!
Your awesome thank you
Thanks :D
yo bro can you please do a game over screen now all the other tutorials aren't as descriptive as yours
Hello, that's a great idea. I've been wanting to make some more tutorials and I'm glad people like them! This is the first suggestion for a tutorial I've gotten so I'll put it on a list, thanks!
When I hover over or click any of the buttons nothing happens.
Wenn ich meinen Mauszeiger Bewege dann bewegt sich meine Player Kamera und wenn ich irgendwo draufklicken will lockt es meinen Mauszeiger im Game.
when i press escape, the game freezes, but the pause menu doesn't pop up. Why?
For people who face this issue in the future, double check u spelled everything right in the script. It basically says "when esc is pressed, enable this ui object". Remember caps sensitivity too.
Ever since i spent 10mins tryna figure out why my "GetComponont" wasnt working im hawkeyeing these spellings
the game doesnt frozes when i open the pause menu
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PauseMenu : MonoBehaviour
{
public static bool paused = false;
public GameObject PauseMenuCanvas;
// Start is called before the first frame update
void Start()
{
Time.timeScale = 1f;
}
// Update is called once per frame
void Update()
{
if (input.Getkeydown(KeyCode.Escape))
{
if(paused)
{
Play();
}
else
{
Stop();
}
}
}
}
void Stop ()
{
PauseMenuCanves.setactive(true);
Time.timescale = 0f;
Paused = true;
}
void Play()
{
PauseMenuCanves.setactive(false);
Time.timescale = 1f;
Paused = false;
}
public void MainMenuButton()
{
SceneManger.LoadScene(something)
}
Can someone help me its not working its the spacing i think
nvm i fixed it but the Void Stop() at 34 is not working said erorr code cs8803
i fiked it but there a Erorr CS0200
fixed again the scrpit has no erorrs but the menu still dosent work?
@@FNAFgorilla its giving me error CS1002
When i got to main menu through the pause menu, it says "no cameras rendering" and the menu stops working. I have a player with a camera in the game scene, and no cameras in the main menu scene, how do i fix it?
Hi, make sure every scene you are using has a camera, because this system changes scenes to manage a lot of the UI!
how do i fix the error where it says "You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings"?
Hi, you need to go to your project settings and change your input system
how can i make it so it also stops playing the music?
same question
Hi, you can add another function on the pause method which references your audio player and calls it to pause, and then play on resume method
To my previous statement, I have resolved half the issue. Now the mouse cursor doesn't disappear but I still can't hit the buttons. Please help
Cursor.visible = false;
In the play function.
I'm having an issue, I've followed everything correctly but i think its my player moving around while I'm in the pause menu is causing it not to work
It has something to do with my movement script, I have to somehow disable it while the pause menu is active.
Hi, yeah you can reference your player movement script on the OnPause event and set it as disabled and enabled
so I remember your fix oculus vids I need help with mine so whenever I log on to my oculus it seems normal but the home page/store it automatically y scrolls down when I play a game my character moves backwards automatically how do you fix this?
Sounds like your oculus controller is stuck srolling down or holding a key down, you could try taking the battery out and restarting it, or try another controller!
thats joystick drift
i dont see the "Pause Menu Canvas" in the Pause Menu (Script)
In the begining, he added this line of code "public GameObject PauseMenuCanvas;", so that we can use the canvas! hope this helps!
the cursor lock dsnt work when I click on resume or options or quit the mouse disappears and i cant prerss on the buutoms but if i die in my game then my game over ui pop up and then i can press on the play options quit button so thats mean i have to everything right just i need in my script something for the cursor i think
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PauseMenu : MonoBehaviour
{
public static bool Paused = false;
public GameObject PauseMenuCanvas;
// Start is called before the first frame update
void Start()
{
Time.timeScale = 1f;
PauseMenuCanvas.SetActive(false);
}
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.Escape))
{
if(Paused)
{
Play();
}
else
{
Stop();
}
}
}
void Stop()
{
PauseMenuCanvas.SetActive(true);
Time.timeScale = 0f;
Paused = true;
Cursor.visible = true;
}
public void Play()
{
PauseMenuCanvas.SetActive(false);
Time.timeScale = 1f;
Paused = false;
Cursor.visible = false;
}
public void MainMenuButton()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
}
}
thanks
i know im 6 months late, but i have a script that i did make with chatgpt because im not good at C# but it makes it so whenever you press esc it makes it so you can move it wherever you want and when you press it again, it locks the mouse again
here it is:
using UnityEngine;
public class MouseToggle : MonoBehaviour
{
private bool isCursorLocked = true;
private void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
isCursorLocked = !isCursorLocked;
if (isCursorLocked)
{
StartCoroutine(ToggleCursorLock());
}
else
{
StopCoroutine(ToggleCursorLock());
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
}
}
private System.Collections.IEnumerator ToggleCursorLock()
{
while (true)
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
yield return new WaitForSeconds(0.1f); // Adjust the delay as needed
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
yield return new WaitForSeconds(0.1f); // Adjust the delay as needed
}
}
private void Start()
{
// Start with the cursor locked
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
}
at 9:59 im getting an error that says CS1061:'GameObject' does not contain a definition for 'setActive'
I have buttons already and they somehow are over my pause menu. How can I change this?
Hi! It has to do with how you place the buttons and layers. Try placing the buttons on the same canvas/panel as the pause menu and make it all under one canvas
Could you tell me why it doesn't work, is it because of the script that makes my character move?
Hi, it depends on many factors but yes first make sure the script is correct by following the video!
It doesnt work when i go to the next level, i copy paste it and the button is not clickable
Hey I have been running into a problem, I have managed to follow every step. Everything works except for when I click the "Main Menu" button on the pause screen, I go back to the main menu but I cannot click anything.
did u watch his last tut?
Same issue here if anyone knows a way to fix it
put a mouse unlock script on an empty object and call it MouseUnlock and make sure its in the main menu scene
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseUnlock : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
UnlockMouse();
}
// Update is called once per frame
void Update()
{
}
void UnlockMouse()
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
}
Thank you
so awesome
:D
What do I do if my options menu is an entirely new scene?
Hi, I don't think you'd want your pause menu options to be another Unity scene, because you'd need to use Scene management.loadScene and when you go back into the game scene everything would restart. I would suggest taking the features of your options menu and adding them into your in-game main menu
its not showing me the pause menu on the Functions
I cant add the script to my menu manager
How do I save using visual studio
Hi, saving is very important. Ctrl + S to save, or file>save :)
bro this can also work in a multiplayer?
Yes, for example with Photon Pun2 it'll work fine you just have to sync the canvas with the player
i got so much freaking errors :C how fix?!?Q??!
will this work with multiplayer or what happens if i pause
Yes this will work with multiplayer! The menu object just has to be part of a networked player prefab
Nice tutorial but i'd rather listen to you rather than the background song :p
Thanks! Yeah I've been working on making the background music quieter, sorry about the past editing mistakes 😅 thanks for the feedback
the script is not working
its giving me error CS1002
it keeps saying that it needs ;
wth
That means at the end of your statements, you need to add a semicolon. So add ; to the end of your statements, you can also see where they go in the video!
@@garrettdeveloper i probably was too slow so i didnt notice that you put that there
lol
@Dylan_Developer What Does It Mean When I Get An Error Saying "The name paused does not exist in the current context"
It means you haven't defined what the name "Paused is", in this case it is a boolean. In my script on line 8, I defined Paused as "public static bool Paused = false" so that we can set the Paused function with the script. Hope this helps!
How do I convert the "Input.GetKeyDown(KeyCode.Escape))" but for the NEW INPUT SYSTEM ?
that still works for me lol
my code isnt working i dont know why if its something stupid i only just started coding
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class NewBehaviourScript : MonoBehaviour
{
public static bool paused = false;
public GameObject PauseMenucanvas;
// Start is called before the first frame update
void Start()
{
Time.timeScale = 1f;
}
// Update is called once per frame
void Update()
{
if (input.Getkeydown(KeyCode.Escape))
{
if(paused)
{
Play();
}
else
{
Stop();
}
}
}
}
void Stop ()
{
PauseMenucanvas.setactive(true);
Time.timescale = 0f;
Paused = true;
}
void Play()
{
PauseMenucanvas.setactive(false);
Time.timescale = 1f;
Paused = false;
}
public void MainMenuButton()
{
SceneManger.LoadScene("Main menu");
}
On SceneManger.LoadScene("Main menu"); you put SceneManger when its SceneManager
@@big_ell123 thanks for the help
@@Coolkidstan no problem
Thank you
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PauseMenu : MonoBehaviour
{
public static bool paused = false;
public GameObject PauseMenuCanvas;
// Start is called before the first frame update
void Start()
{
Time.timeScale = 1f;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (paused)
{
Play();
}
else
{
Stop();
}
}
}
void Stop()
{
PauseMenuCanvas.SetActive(true);
Time.timeScale = 0f;
paused = true;
}
public void Play()
{
PauseMenuCanvas.SetActive(false);
Time.timeScale = 1f;
paused = false;
}
public void MainMenuButton()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
}
}