Arrays

Checked with version: 4.0

-

Difficulty: Beginner

-

Date: 13 Mar 2014

Using arrays to collect variables together into a more manageable form.

Arrays

Code snippet

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);
        }
    }
}
#pragma strict

public var players : GameObject[];

function Start ()
{
    players = GameObject.FindGameObjectsWithTag("Player");
    
    for(var i : int = 0; i < players.Length; i++)
    {
        Debug.Log("Player Number "+i+" is named "+players[i].name);
    }
}
import UnityEngine
import System.Collections


public class Arrays(MonoBehaviour):

    public players as (GameObject)

    
    private def Start():
        players = GameObject.FindGameObjectsWithTag('Player')
        for i in range(0, players.Length):
        
            Debug.Log(((('Player Number ' + i) + ' is named ') + players[i].name))
Instantiate
Invoke

Related documentation

Array (Script Reference)