- Home /
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!
Answer by Cherno · Aug 20, 2014 at 03:20 PM
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.
Open the Edit->Project Settings->Input window, and create a new input for your joystick button, and then use it's name in the Update functiln, and see if it still doesn'T work.
The input for that button works because it fires when GetButton is used.
Answer by JxWolfe · Oct 08, 2018 at 04:48 PM
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.
Your answer
Follow this Question
Related Questions
While I'm using joystick I also touching screen how can I fix it ? 0 Answers
Alternative to OnMouseDown() 2 Answers
How can i rotate only Z axis of Player. 1 Answer
GetButtonDown problem | C# 0 Answers