What is wrong with this code? (an IF statement)

For some reason I can’t get this code to work. I’ve stripped it back to nothing, and even tried the code in an entirely new scene to rule out anything else.

var inair : int = 0;


function Update () {

if (Input.GetButtonDown("Fire1")) {
inair = 1;
}

Debug.Log(inair);

}

The idea is that inair should be 0 until I press fire, at which point it should be changed to 1. For some reason it always seems to run the Fire code once upon starting the program regardless of whether I actually press the button or not. I’m new to Unity, but I’m not new to programming, and it’s only an IF statement. This is driving me crazy. What am I doing wrong here?

Are you getting your debug statement being hit on startup or is inair just defaulting to 1 rather than 0?

I think I just found the problem. It looks like the default setup for Fire1 includes an alternate button of Mouse0, which I assume is left click, which of course I’m using to click the play button.
I wish Unity wouldn’t try to do everything for you, because I just wasted half a day on this problem because of a default setting I didn’t know about buried in a menu.

That sounds about right, we had an issue similair to that a while back. While you were in there you didn’t figure out how to setup the input axes and buttons in code rather than in the GUI did you? I want to be able to set them at run time