Question by
Joebear · Dec 14, 2017 at 09:57 PM ·
javascriptgun scriptgunfire
Gunshot not working?
I'm following a YouTube tutorial (https://www.youtube.com/watch?v=LVztnx4JHVQ&lc=z22jvzjw4zfmwbnri04t1aokgwf3ymvnqjg13040mqjtrk0h00410.1513252262818829) on creating an FPS and I've run into a problem. Nobody in the comments seems to know how to fix it. I have a gun that you can get that isn't automatic and it works fine. This one is automatic, but only the first shot does any damage to the enemy. What have I done wrong and how can I fix this? It's in Javascript by the way. This is my script:
var TheSMG : GameObject;
var SMGSound : AudioSource;
var MuzzleFlash : GameObject;
var AmmoCount : int;
var Firing : int;
function Update () {
AmmoCount = GlobalAmmo.LoadedAmmo;
if (Input.GetButton("Fire1")) {
if (AmmoCount >= 1) {
if (Firing == 0) {
SMGFire();
}
}
}
}
function SMGFire() {
Firing = 1;
GlobalAmmo.LoadedAmmo -= 1;
SMGSound.Play();
TheSMG.GetComponent("Animator").enabled = true;
yield WaitForSeconds(0.1);
TheSMG.GetComponent("Animator").enabled = false;
Firing = 0;
}
Comment