i want to have it were somthing happens after said amount of seconds and then reset and repeat. I would like to use this to make a shooting part in my game so that when a tower shoots at an enemy it’s bullets come out with paced and not just like a lazer.
http://answers.unity3d.com/questions/273094/unity3d-timer-request.html
http://answers.unity3d.com/questions/11458/how-to-make-a-timer-in-the-game.html
http://answers.unity3d.com/questions/11939/count-down-timer.html
http://answers.unity3d.com/questions/225213/c-countdown-timer.html
You can achieve that using coroutines:
public float Interval = 2f;
private bool _shooting;
private void SomeMethodCalledWhenEnemyEntersArea() { // for instance OnTriggerEnter
_shooting = true;
StartCoroutine(ShootAndWait(Interval));
}
private void SomeMethodCalledWhenEnemyLeavesArea() { // for instance OnTriggerExit
_shooting = false;
}
IEnumerator ShootAndWait(float interval) {
while(shooting) {
Shoot();
yield return new WaitForSeconds(interval);
}
}