- Home /
Question by
mr4355 · Feb 04, 2019 at 01:05 PM ·
triggerscoroutinesspherecollider
how to use Triggers inside coroutines?
Check the following code snippet:
IEnumerator SpawnBomb()
{
while (level)
{
yield return new WaitForSeconds(bombSpawnWait);
bombSpawnPosition.x = Random.Range(-45.0f, 45.0f);
bombSpawnPosition.z = Random.Range(-45f, 45f);
Vector3 obstacleSetPosition = new Vector3(bombSpawnPosition.x, 40f, bombSpawnPosition.z);
Quaternion obstacleSetRotation = Quaternion.identity;
GameObject bombNow = Instantiate(bomb, obstacleSetPosition, obstacleSetRotation);
***yield return new WaitForSeconds(bombStayTime);
Destroy(bombNow, 0); // Destroying the bomb after 'bombStayTime' in seconds
MySoundEngine.Instance.DestroySounds(3); // Bomb SFX from ext. method
}
}
The code works and all the variables are assigned.
Here, I also want to check overlapping objects (obstacle) within a sphere collider (that I added on the bomb prefab and marked the 'isTrigger' to true) and destroy that object as well.
Any thoughts??
Comment