if ( input.. bool var) doesnt work...?

I try to make a 3d-person view.

var thirdPersonView;
function Start () {
SelectWeapon(0);
thirdPersonView = false;}

But whats not work is:

if (Input.GetKeyDown ("q")  thirdPersonView== false)
		{
		BroadcastMessage("CameraSwitch");
		thirdPersonView = true;
		Debug.Log("false");
		}
		
		if (Input.GetKeyDown ("q")  thirdPersonView== true)
		{
		BroadcastMessage("CameraSwitch");
		thirdPersonView = false;
		Debug.Log("true");
		}

when pressing “q” the debug.log says true
But it should say false and activate the cameraswitch

what i am doing wrong?

You must have something else setting it to true, because that will work fine. Although you should define thirdPersonView like this:

var thirdPersonView : boolean;

–Eric

Well, it seems that you set thirdPersonView to true and then to false again (and your debug log probably says false and true at the same frame.
Try adding “else” to the second “if”:

if (Input.GetKeyDown ("q")  thirdPersonView== false)
{
...
}     
else if (Input.GetKeyDown ("q")  thirdPersonView== true)
{
...
}

thank you both, I ll try it :slight_smile:

No, because GetKeyDown only returns true once, until the key is released. Although adding “else” is still a good idea since it’s faster than evaluating both if statements all the time. Actually, ideally it would be best to check GetKeyDown once and put the thirdPersonView check inside that.

–Eric

Actually, GetKeyDown returns true as many times as you need to call it in the single Update. It means that one frame (not one call) it is true (no matter how many times you call it), but in the next frame it will be false.

Oops, quite right…not sure what I was thinking there.

–Eric