- Home /
Xbox One controller trigger to fire a weapon
I'm looking to fire my gun with an xbox controller but I'm having issues... because the Xbox triggers are axis' then they act as if in a constant fire state and fires every frame. I have used javascript as my firing script but have no idea how to get my weapon to fire 1 bullet when pressed and then when depressed it resets and i can fire my weapon again any ideas?
var MuzzleFlash : GameObject;
function Update ()
{
if (GlobalAmmo.LoadedAmmo >= 1)
{
if(Input.GetButtonDown("Fire1") || Input.GetAxis(TriggerFire))
{
var gunsound : AudioSource = GetComponent.<AudioSource>();
gunsound.Play();
MuzzleFlash.SetActive(true);
MuzzleOff();
GetComponent.<Animation>().Play("GunShot");
GlobalAmmo.LoadedAmmo -=1;
}
}
}
function MuzzleOff()
{
yield WaitForSeconds(0.15);
MuzzleFlash.SetActive(false);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612152431im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I test with an XBox 360 controller without building first? 1 Answer
Input.GetJoystickNames gives incorrect index with multiple controllers 1 Answer
Joystick ID when connecting and disconnecting 0 Answers
Xbox DPad works but is unreliable and requires multiple presses to register any input 0 Answers
How to properly do Twin Stick shooter controls with an XBOX controller? 1 Answer