The var “sta_sparando” remains on after i release left mouse button
#pragma strict
var suono_sparo : AudioClip;
var munizioni = 100;
var firerate = 0.1;
var sta_sparando=false;
var muzzleflash : ParticleSystem;
function Start () {
muzzleflash = muzzleflash.GetComponent.<ParticleSystem>();
muzzleflash.Stop(true);
}
function Update() {
if(Input.GetMouseButton(0)&&sta_sparando==false){
fire();
}
}
function fire(){
var ray: Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit: RaycastHit;
muzzleflash.Play(true);
sta_sparando=true;
print("boom");
AudioSource.PlayClipAtPoint(suono_sparo, transform.position);
if (Physics.Raycast(ray, hit)){
Debug.DrawLine(ray.origin, hit.point);
if (hit.transform.tag == "Zombie"){
var zombie_colpito = hit.collider.gameObject;
var zombie_life=zombie_colpito.GetComponent(AiZombie);
zombie_life.salute-=15;
print("Zombie colpito");
}
if (hit.transform.tag == "Cadavere_zombie"){
var cadavere_colpito = hit.collider.gameObject;
var rb = cadavere_colpito.GetComponent(Rigidbody);
rb.AddForce(transform.forward * 10,ForceMode.Impulse);
print("Cadavere colpito");
}
}
yield WaitForSeconds(firerate);
muzzleflash.Stop(true);
sta_sparando=false;
}