I am making an oldfashioned sci-fi style shootemup and I want to make the main gun fire about every 0.5 seconds. This is what I have so far.
using UnityEngine;
using System.Collections;
public class laserblast : MonoBehaviour {
public Rigidbody laser;
public Rigidbody ship;
void Update () {
if (Input.GetKey("d"))
{
Instantiate (laser,ship.position,ship.rotation);
}
}
}
as you can see, when I press “d”, laser fires from the ship. My problem is that another laser fires every frame and I would like to know how to control that so the laser comes in only every half second. Thank you.