Hey can someone please tell me how I can show a canvas by pressing esc? (Im a begginer)
And wen I press a button that opend a canvas It will close the all other canvas.
(Im still a begginer)
And sorry for my Englishe
Hey can someone please tell me how I can show a canvas by pressing esc? (Im a begginer)
And wen I press a button that opend a canvas It will close the all other canvas.
(Im still a begginer)
And sorry for my Englishe
//Attach your canvas to this variable in inspector
public GameObject canvasObj;
//This will check if your game is paused (we'll set it)
bool gamePaused;
void Update()
{
//Reading input for ESCAPE key, and by saying gamePaused = !gamePaused, we switch the bool on and off each time the Keycode is registered!
if(Input.GetKeyDown(KeyCode.Escape))
gamePaused = !gamePaused;
//Now we enable and disable the game object!
if(gamePaused)
canvasObj.SetActive(true);
else
canvasObj.SetActive(false);
}
A useful link for you:
Let me know/reply here if you need any further help! ![]()
Hey, Thx for help men it works Fantastic:)
You are more than welcome! ![]()
Let me know in case you need any further assistance!
Hey, I got another question how can you lock the cursor with escape.
what I actually want is a the scrip here above but wen you press escape it wil set the game to pause and it will show the cursor. but I really don’t know how you can do that. Do you know how you can do that?
I found this link for you, let me know if it’s good enough:
Hi Sykoo,
Your explanation is very short but very helpful and easy to understand.
I am a beginner too, seeking this info just found your help here.
Perfect.
I tried reading UnityDoc but sometime it’s not easy to understand.
But reading how to use SetActive from your code above, I just suddenly realized cause you comments are so straight and simple.
Thanks so much.
//Pause System - To enable mouse when you press Escape.
void Update() {
if (!gamePaused)
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
mouseLook(); //All mouse / moviment or other scripts
}
else
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
}