StartCoroutine Flashcards
1
Q
private void OnTriggerEnter(Collider other)
{
If (other.CompareTag(“Powerup”))
{
Destroy(other.gameObject);
hasPowerup = true;
StartCoroutine(PowerupCountdownRoutine());
powerupIndicator.gameObject.SetActive(true);
}
}
A
IEnumerator PowerupCountdownRoutine() { yield return new WaitForSeconds(7); hasPowerup = false; powerupIndicator.gameObject.SetActive(false); }
2
Q
Start()
{
StartCoroutine(SpawnTarget());
}
A
IEnumerator SpawnTarget() { while(true) { yield return new WaitForSeconds(spawnRate); int index=Random.Range(0,targets.Count);
Instantiate(targets[index]);
}
}