IEnumerator Ornek()
{
Debug.Log("1");
yield return new WaitForSeconds(2);
Debug.Log("2");
yield return new WaitForSeconds(5);
Debug.Log("3");
}
StartCoroutine(Ornek());
Çıktı:
1
//2 saniye sonra
2
//5 saniye sonra
3
Kullanım alanları: power up, skill, random süre üretip — enemy üretme, kullanım taktikleri(Move — WASD, 2sn sonra Attack — Sol click)…
power up örneği:
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("PowerUp"))
{
hasPowerup = true;
Destroy(other.gameObject);
StartCoroutine(PowerupCountdownRoutine());
powerupIndicator.gameObject.SetActive(true);
}
}
IEnumerator PowerupCountdownRoutine()
{
yield return new WaitForSeconds(7);
hasPowerup = false;
powerupIndicator.gameObject.SetActive(false);
}
