I am trying to make a pause menu and it pauses when ESC is pressed. When ESC is pressed the mouse is supposed to show and be able to click an exit button if you want to leave the game. Unity says else is not supposed to be in the script. How would I use “else”. Thanks in advance
P.S.-sorry if this is a noob question I’m new.
void Update (){
Cursor.lockState
else
{
if (Input.GetKeyDown("Escape"))
Screen.lockCursor = false ;
Cursor.visible ;
}
}
}
I think you should learn a bit more programming in C#.Else should be used under if.Which means ‘else’ will execute anything not satisfied by ‘if’ condition
if(condition)
{
//Statements
}
else
{
//Statements
}
First you should decide how you going to achieve the pause system.Is it by disabling all the updation by code or you can set the timescale in unity to 0 pause the frame updation.You should keep in mind that when you set Time.timescale=0.0f, the FixedUpdate functions will stop working.
void Start()
{
//Lock the cursor
Screen.lockCursor = true;
}
void Update()
{
//If escape is pressed
if (Input.GetKeyDown(KeyCode.Escape))
{
//If game not paused,pause the game and show the cursor
if(Time.timeScale>0.0f)
{
//Show the cursor
Screen.lockCursor = false ;
//Pause the game here
Time.timeScale=0.0f;
}
else //Else resume the game and hide the cursor
{
//Show the cursor
Screen.lockCursor = true;
//Pause the game here
Time.timeScale=1.0f;
}
}
}
Hope this helps you to get started…
All you need to execute if the condition if() is true needs to be encapsulated between {}
The problem there is that your else statement has been lost out of the scope of the if statement
Lets try this
void Update (){
if (Input.GetKeyDown("Escape"))
{
Screen.lockCursor = false ;
Cursor.visible ;
}
else
{
}
}
}