Game Not Pausing

//Pause/Unpause Game
	if(Input.GetButtonDown("Q")  gamePaused == false){
	
		Time.timeScale = 0;
		gamePaused = true;
	}
	
	if(Input.GetButtonDown("Q")  gamePaused == true){
	
		Time.timeScale = 1;
		gamePaused = false;
	}

Does nothing. gamePaused does not change. I’ve checked, and the input is set up correctly.

Rganks.

Try GetButtonUp

For one, that wouldn’t make a difference. It’s also not what I want.

What happens if you just do

if(Input.GetButtonDown("Q")){
        Debug.Log("Q pressed");
}

?
Maybe you can post your full script?

That of course works fine. The issue here is that the time scale is not changing.

So…

Presumably the first if condition is running, setting ‘gamePaused’ to true, and then the second if condition is running straight away.

You could of course check this by adding two Debug.Log statements.

That is exactly what is happening. It is falling through the second if straightaway.
Put an else in between them.

Got it. Thanks a ton.

I have indeed noticed this problem, “” does not work most (if not all) of the time, so you need a second if statement. “Else” also won’t help, it requires an alternate set of requirements to be filled (it basically says “or”, not “and”) so if{ if{ }} is how to do it.

Sorry to sound mean, but everything you said was wrong.

Maybe you just need to change “GetButton…” to “GetKey…”…

edit:

oh, so I think this is not the problem. Good luck.

Explain, please. What I said is what I have observed as a coder, so it is based off of experience. Again, please explain.

In OP’s case, the quickest fix is to put an else. He already has the “alternate set of requirements”.
“else” does not basically say “or”; It says “otherwise”, or “Now for something completely different”.
Allow me to walk you through the OP’s code

//Pause/Unpause Game
//if the Q key was depressed this frame  the gamePaused variable is false
    if(Input.GetButtonDown("Q")  gamePaused == false){
    //do our stuff: pause the game, and set the flag to true
        Time.timeScale = 0;
        gamePaused = true;
    }

    
//if the Q key was depressed this frame  the gamePaused variable is true
//without the else, it will always flow into this if
//if gamePaused were false, then the first if will change it true
//if it were true, then it will not have gone in the first if, but still come through here
    if(Input.GetButtonDown("Q")  gamePaused == true){
        Time.timeScale = 1;
        gamePaused = false;
    }

Now for an efficiency fix, which may look like Orbitus’s suggest answer of an if inside an if, but it’s not for the reasons of treating elses like ors and ands being faulty.

if(Input.GetButtonDown("Q")) {
    Time.timeScale = 0;
    if(gamePaused) {
        Time.timeScale = 1;
    }
    gamePaused = !gamePaused;
}

Cheers!

Edit: Sorry noisecrime… great minds think alike and at the same time

Edit: Bah, Democre replied as I was typing out mine, basically saying the exact same thing.

Then you have observed incorrectly.
There is nothing wrong with ‘’ it works perfectly fine. If you have code with a conditional statement using which doesn’t work as expected then either you expectations/logic (as in the case of the OP) or code is wrong.

As for the OP the problem is simple, if the first conditional check evaluates to true, then the second conditional must also evaluate to true due to the change of ‘gamepaused’ by the first, resulting in both if statements being executed, thus pausing then un-pausing the game in a single update. Hence why an else check is required.

For example

Assume that ‘Input.GetButtonDown(“Q”)’ is true and gamePaused is false.

The first if statement will evaluate to true and will change gamePaused to true.

Since ‘Input.GetButtonDown(“Q”)’ will not change its value half-way through Update it is still true for the second if statement and as the previous conditional check set gamePaused to true, the second if statement now also evaluates to being true.

Its would be easy to check, just add a Debug.Log() statement to each conditional check and you’ll see that is what is happening.

Normally in these situations I would find it easier to split the check into a hierarchy chain e.g.

    if(Input.GetButtonDown("Q") )
    {    
		if( gamePaused == false)
		{
	        Time.timeScale = 0;
	        gamePaused = true;
		}
	    else
	    {
	        Time.timeScale = 1;
	        gamePaused = false;
	    }
    }

Sorry if you guys didn’t understand, but at this post I had meant that I got it working. No more help needed.

I was just letting Orbitus know that his logic was completely incorrect. Thanks everyone for explaining it to him.

I meant “else” as in “else if,” people. My issue was forgetting a single word.

Not hatin’, else never means or, with or without an if.

Compound meanings. “Otherwise if _______” is the same as “or ________”.

Regardless of what you meant, the rest of your post was still incorrect. And for your information, else if works perfectly fine.