- Home /
I solved the question :)
How to randomly spawn object without spawning the previous object in a row?
Hello; Firstly i'm working on a mobile game let me clarify my game basicly we have one player and falling objects. Your mission is collecting the dropping objects and gain point per collected object. We wanted to add falling power ups for adding diversity in game. Our power ups system working correctly but our problem coming up with "spawning the powerups". I wrote a simple randomly spawning powerups system but i want to check if it's spawned twice in a row before spawn it. So how can i check this?
Here is my spawn code:
IEnumerator spawnPWU()
{
yield return new WaitForSeconds(15f);
while (true)
{
for (int i = 0; i < 1; i++)
{
Vector2 vec = new Vector2(Random.Range(randompos.x, -randompos.x), randompos.y);
Instantiate(powerUps[rand], vec, Quaternion.identity);
yield return new WaitForSeconds(7.5f);
}
yield return new WaitForSeconds(7.5f);
}
}
İf more information needed about code let me know.
Follow this Question
Related Questions
Spawning prefab on x axis inside the camera 2 Answers
Random Spawn, Random Prefab 2 Answers
Spawning Objects Using An Array. 1 Answer
Problem: Random Instantiating more than one prefab? 1 Answer