unity array of gameobjects
If you want to create an array of this gameobject, you can do this as follows:
int Size = 10; //Number of objects
GameObject[] Tiles = new GameObject[Size];
Let's assume you have created a prefab, called "Tile". If we want to initialize the array's gameobjects, we could do it like this:
//Loop for the entire size of the array, 10 in this case
for (int i = 0; i < Size; i++)
{
//Create the game object
Tiles[i] = GameObject.Instantiate (Resources.Load ("Tile")) as GameObject;
//Position it in the scene
Tiles[i].transform.position = new Vector3(i * 0.32f, 0, 0);
}
If you assign the following script to the Start() function of a gameobject in your scene, you will see 10 Tile prefab objects appear when you Run your game.
Are there any code examples left?
New code examples in category Other
-
Other 2023-03-27 22:50:10 how to select the whole line in vscode with keyboard shortcut
-
Other 2022-03-27 22:45:24 income of a web developer
-
Other 2022-03-27 22:35:01 \pyrcc_main.py: File does not exist 'resources.qrc'
-
Other 2022-03-27 22:30:45 rick roll embed code
-
Other 2022-03-27 22:20:08 Circuit_04_Potentiometer
-
Other 2022-03-27 22:20:05 iterative power
-
Other 2022-03-27 22:15:11 flutter run all
-
Other 2022-03-27 22:10:05 when is karlson release
-
Other 2022-03-27 22:10:02 wp .htaccess example
-
Other 2022-03-27 22:00:08 bash pause in file read line by line