Quantcast
Channel: Latest Questions by eeveelution8
Viewing all articles
Browse latest Browse all 100

weapon isn't removing ammo when firing, but the script behaves normally otherwise.

$
0
0
the script I have for a pistol should remove the amount of ammo equal to the firecost, the script being, var Attack1 : GameObject; var Attack2 : GameObject; var sound1 : AudioClip; var sound2 : AudioClip; var player : GameObject; var holder : ammomanager; var ammo : int = 0; var maxammo : int = 0; var firecost1 : int = 0; var firecost2 : int = 0; var isfiring : boolean = false; var Firerate1 : float = 0; var Firerate2 : float = 0; function Update () { player = GameObject.FindGameObjectWithTag("Player"); holder = player.GetComponent(ammomanager); ammo = holder.clips; if(Input.GetKeyDown(KeyCode.Mouse0)){ if(ammo >= firecost1){ if(isfiring == false) { var instance1 : GameObject = Instantiate(Attack1, transform.position, transform.rotation); audio.clip = sound1; audio.Play(); isfiring = true; ammo = ammo - firecost1; wait1(); } } } else if(Input.GetKeyDown(KeyCode.Mouse1)){ if(ammo >= firecost2){ if(isfiring == false) { var instance2 : GameObject = Instantiate(Attack2, transform.position, transform.rotation); audio.clip = sound2; audio.Play(); isfiring = true; ammo = ammo - firecost2; wait2(); } } } if(ammo < 0){ ammo = 0; } if(ammo > maxammo){ ammo = maxammo; } } function wait1(){ yield WaitForSeconds (Firerate1); isfiring = false; } function wait2(){ yield WaitForSeconds (Firerate2); isfiring = false; } The ammo manager script just has 9 int values and nothing else. the gun behaves as expected, but isn't deducting ammo. Is the syntax correct?

Viewing all articles
Browse latest Browse all 100

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>