by Guest » 05 Feb 2025, 02:03
Ich habe den folgenden Code verwendet, um 9 GameObjects zu instanziieren. Weiß jemand, wie das geht?
Vielen Dank im Voraus für jede Hilfe, die Sie geben können.
Code: Select all
public int width = 10;
public int height = 10;
public GameObject[] tilePrefabs;
void Start()
{
GenerateLevel();
}
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");
}
}
Ich konnte keinen Weg finden, um sicherzustellen, dass jedes GameObject eine nochmalige Anzahl von Malen erscheint, was bedeutet>
Ich habe den folgenden Code verwendet, um 9 GameObjects zu instanziieren. Weiß jemand, wie das geht?
Vielen Dank im Voraus für jede Hilfe, die Sie geben können.[code]public int width = 10;
public int height = 10;
public GameObject[] tilePrefabs;
void Start()
{
GenerateLevel();
}
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");
}
}
[/code]
Ich konnte keinen Weg finden, um sicherzustellen, dass jedes GameObject eine nochmalige Anzahl von Malen erscheint, was bedeutet>