I have been using the following code to instantiate 9 gameObjects. It works beautifully, but I want to be able to ensure that each object is instantiated an even number of times. Does anyone know how to do this? Thanks in advance for any help you can give.
void GenerateLevel()
{
for (int x = -10; x < width; x++)
{
for (int y = -4; y < height; y++)
{
for (int i = 0; i < tilePrefabs.Length; i++)
{
if (Random.value > 0.5f) // 50% chance to place a tile
{
int randomIndex = Random.Range(0, tilePrefabs.Length);
Vector2 position = new Vector2(x, y);
Instantiate(tilePrefabs[randomIndex], position, Quaternion.identity);
}
}
}
}
}
void FixedUpdate()
{
if ((GameControl.control.matches >= 69) && (GameControl.control.matches < 207))
{
SceneManager.LoadScene("Level2");
}
}
I could not find a way to ensure each GameObject appears an even number of times, which means that unused objects remain after any operation that is implemented.