I am trying to limit the rate of fire for my gun. I use this script:
function Update ()
{
machineflash = GameObject.FindWithTag("machineflash");
// raycast settings
var direction = transform.TransformDirection(Vector3.forward);
var hit : RaycastHit;
var localOffset = transform.position;
// check to see if user has clicked
if(Input.GetButton("Fire1"))
{
{
// if so, did we hit anything?
if (Physics.Raycast (localOffset, direction, hit, 400))
{
// just so we can see the raycast
Debug.DrawLine (localOffset, hit.point, Color.cyan);
// print to console to see if we have fired
print("we have fired!");
// send damage report to object
hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
}
AudioSource.PlayClipAtPoint(gunshot,transform.position);
Instantiate (muzzleflash, machineflash.transform.position, transform.rotation);
}
}
But whenever I try to put a WaitForSeconds, it says that function Update() cannot be a coroutine. How can I fix this.