Randomly Placing Prefabs on a Grid
Hello,
I want to randomly place prefabs at specific locations (think a 5x3 grid) at random times (ranging from 5 to 15 seconds). However, the items should only be allowed to be place at a grid point if there isn't already an item there.
The way I have it coded now uses an array based on grid location that keeps track of if an item is currently in that spot (an array of booleans).
I have a set of if statements that check if THAT grid spot was chosen AND if there isn't already an item there. But, it seems to fail because when I test items get placed multiple times at the same grid location.
For example:
BoardLocation = Random.Range (1, 16);
if (BoardLocation == 1 && SpotTaken [0] == false) {
XYLocation.Set (0, 12, 0);
SpotTaken [0] = true;
return XYLocation;
}
Any ideas why this isn't working?
Thanks
Your answer
Follow this Question
Related Questions
randomly shoot using number generator 0 Answers
Instantiated Particle System not random 4 Answers
How can I Instantiate an object with a random y rotation but in 90 degree increments? 1 Answer
Trying to make a field of meteors forever, but I can tell I'm doing it horribly 0 Answers
Spawn enemies so they aren't instantiated on top of each other (C#) 2 Answers