Ich habe eine Frage zum Instanziieren von GameObjects

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Ich habe eine Frage zum Instanziieren von GameObjects

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>

Top