- Home /
Pause Problem
Hey guys im working on a game where u need to dodge other cars that are driving towards you. I have a menu working and all but somehow i cant manage to make my pause script working.
this is my script.
var isPaused : boolean = false;
function Update()
{
if(Input.GetKeyDown("Enter") && isPaused)
{
print("Paused");
Time.timeScale = 0.0;
isPaused = true;
}
else if(Input.GetKeyDown("Enter") && isPaused)
{
print("Unpaused");
Time.timeScale = 1.0;
isPaused = false;
}
}
This should solve the given section of code. I'd change it to an Answer.
Answer by Graham-Dunnett · Dec 09, 2011 at 04:46 PM
Did you mean to have a "not" operator before the first isPaused, so the logic reads if-enter-pressed-and-not-paused?
var isPaused : boolean = false;
function Update()
{
if(Input.GetKeyDown("Enter") && !isPaused) // <- Right here!
{
print("Paused");
Time.timeScale = 0.0;
isPaused = true;
}
else if(Input.GetKeyDown("Enter") && isPaused)
{
print("Unpaused");
Time.timeScale = 1.0;
isPaused = false;
}
}
I took the liberty of transfor$$anonymous$$g comment to answer and including the suggested fix into code, just because IT'S FRIDAY NIGHT!
Your answer
![](https://koobas.hobune.stream/wayback/20220613061930im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Pause menu script, mouse not hiding 1 Answer
add lockcursor to pause menu script?? 2 Answers
Pause menu doesn't pause everything 0 Answers
Halt function midway until player presses 'OK' then continue 1 Answer
pause menu on android phone 1 Answer