- Home /
Two keys-Same function
I'd like to have two keys pause the game. The "p" and "Escape" keys to be specific.
The script below is working for both of these, but I'm sure it's double the amount of script necessary, and so I'd like to know how I can have both keys mentioned in the first if statement?
This my first UnityAnswers question, so please let me know if I have not been clear enough.
//Pause the game with the "P" key
if(Input.GetKeyDown("p") && paused == false)
{
paused = true;
Time.timeScale = 0;
}
else if(Input.GetKeyDown("p") && paused == true)
{
paused = false;
Time.timeScale = 1;
}
//Pause the game with the "Escape" key
if(Input.GetKeyDown(KeyCode.Escape) && paused == false)
{
paused = true;
Time.timeScale = 0;
}
else if(Input.GetKeyDown(KeyCode.Escape) && paused == true)
{
paused = false;
Time.timeScale = 1;
}
Answer by whydoidoit · Mar 24, 2013 at 09:54 PM
You can combine the conditions like this:
if((Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown("p")) && paused == false)
{
...
}
Your answer
Follow this Question
Related Questions
how do I make it so that my game only starts after the player presses Jump? 0 Answers
Digital Hardware Key - Android 1 Answer
is there a way to change input keys at runtime 0 Answers
How Can I Fight Button Mashing - Need To Slow Down Input Rate 1 Answer
Time.timeScale doesn't stop void update() from beeing run 1 Answer