GetButtonDown doesn't work with Joystick inputs

I’m trying to make my spaceship fire only once when the Fire trigger is pulled on a joystick, but GetButtonDown doesn’t seem to work.

function Update () {

	// Put this in your update function
	if (Input.GetButton("JoyFire")) {
     	
    	var clone : Rigidbody;
    	clone = Instantiate(projectile, transform.position, transform.rotation);
    	clone.velocity = transform.TransformDirection (Vector3.forward * speed);
 	}
}

This is code that works, but rapid fires projectiles… which would be fine for certain weapon types, but I want this particular weapon to only fire once when triggered. If I change Input.GetButton(“JoyFire”) to Input.GetButtonDown(“JoyFire”), nothing happens when the trigger is pulled.

I’m guessing this is a limitation in how joysticks are handled? Anyway, looking for suggestions on this one. Thanks!

No, Input.GetButtonDown should register your joaystick button once, just as it should.

Put a Debug.Log line directly after checking if the button has been pressed to see if it really registers the input, or if just the instantiating bit doesn’t work.

I have found two solutions that worked for me. The best one is to change your axe’s settings. You have to set it’s “type” to a key or mouse button rather than a joystick axe. I did that and then i was able to use Input.GetButtonDown(“AxeName”)


if that didn’t work you could use Input.GetKeyDown(“joystick button 5”) instead. These doesn’t allow you to have an axe to be able to change in the editor, but it will work.

–Hope that helps you.