- Home /
Random Enemy enabled in given area after random time
I have 3 disabled game objects. I want to make it so after a random amount of time, one of the objects are enabled. Is there any way to do this?
Answer by Priyanka-Rajwanshi · Mar 25, 2018 at 09:23 AM
Use Random.Range for determining the random value of Time between min and Max range.
float timeToEnable = Random.Range(minTime, maxTime);
Use Invoke or StartCoroutine for enabling after 'timeToEnable' seconds.
Invoke("EnableEnemy", timeToEnable);
Take a list of Disabled enemies gameobject- 'Enemies'. Get a random enemy by:
int randomEnemy = Random.Range(0, Enemies.Count);
Enemies [randomEnemy].SetActive(true);
You can remove the already enabled Enemy form the list by
Enemies.RemoveAt(randomEnemy);
Your answer
Follow this Question
Related Questions
30 Objects all firing at exactly the same time and not randomly 1 Answer
Image for a quarter of a second 1 Answer
Wait Random Amount of Seconds? 3 Answers
Unity and music tracks - load track at certain point and fading tracks in and out 1 Answer
How to have a object move in a direction then change by random number 1 Answer