Ich habe eine Frage zum Instanziieren von GameObjectsC#

Ein Treffpunkt für C#-Programmierer
Guest
 Ich habe eine Frage zum Instanziieren von GameObjects

Post by Guest »

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>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post