Hello! So im trying to write a script where a bullet is being instantiated every 5 seconds… The problem here is that when the game starts, it waits for 5 seconds, then immediately instantiates bullets every frame and doesnt wait for 5 seconds anymore. What’s wrong with my script?
public class shoot : MonoBehaviour {
public GameObject LaserBulletPrefab;
void Update () {
StartCoroutine(ShootTheThing(5f));
}
IEnumerator ShootTheThing(float waitSeconds)
{
yield return new WaitForSecondsRealtime(waitSeconds);
print("Shooting...");
Instantiate(LaserBulletPrefab, transform.position, transform.rotation);
}
}
It also prints out “Shooting…” every frame.