I am working on my first autofire script,but I came across a problem…
#pragma strict
public var rocketPrefab : Rigidbody;
public var barrelEnd : Transform;
var gun :GameObject;
var muzzle :GameObject;
muzzle.active=false;
var gunshotlight :Light;
gunshotlight.enabled=false;
function Muzzle()
{
muzzle.active=true;
gunshotlight.enabled=true;
yield WaitForSeconds (0.01);
muzzle.active=false;
gunshotlight.enabled=false;
}
function repeat(){
yield WaitForSeconds (0.01);
InvokeRepeating("autofire", 0, 0.01);
}
function autofire(){
var rocketInstance : Rigidbody;
rocketInstance = Instantiate(rocketPrefab, barrelEnd.position, barrelEnd.rotation);
rocketInstance.AddForce(barrelEnd.forward * 5000);
gun.GetComponent.<AudioSource>().Play();
gun.GetComponent.<Animation>().Play();
Muzzle();
repeat();
}
function Update ()
{
if(Input.GetButton("Fire1"))
{
autofire();
}
}