Answers for "unity array of arrays"

5

unity define array

int[] arr1 = new int[3]; 
 // Create an integer array with 3 elements
 var arr2 = new int[3]; 
 // Same thing, just with implicit declaration 
 var arr3 = new int[] { 1, 2, 3 };  
 // Creates an array with 3 elements and sets values.
Posted by: Guest on April-21-2021
7

unity array c#

string[ ] familyMembers = new string[]{"John", "Amanda", "Chris", "Amber"} ; 
 
string[ ] carsInTheGarage = new string[] {"VWPassat", "BMW"} ; 
 
int[ ] doorNumbersOnMyStreet = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; 
 
GameObject[ ] carsInTheScene = GameObject.FindGameObjectsWithTag("car");
Posted by: Guest on April-12-2020
1

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.
Posted by: Guest on March-20-2021
0

array in c# unity

using UnityEngine;
using System.Collections;

public class Arrays : MonoBehaviour
{
    public GameObject[] players;

    void Start ()
    {
        players = GameObject.FindGameObjectsWithTag("Player");
        
        for(int i = 0; i < players.Length; i++)
        {
            Debug.Log("Player Number "+i+" is named "+players[i].name);
        }
    }
}
Posted by: Guest on January-30-2021
-1

unity array c#

GameObject[ ] carsInTheScene = GameObject.FindGameObjectsWithTag("car");
Posted by: Guest on April-12-2020

Browse Popular Code Answers by Language