Scripting
Beginner

Arrays

Checked with version: 4.0

-

Difficulty: Beginner

-

Date: 13 Mar 2014

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

Arrays

Beginner Scripting

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)
Got it

The Unity Software License Agreement and Privacy Policy have been updated.

We use cookies to ensure that we give you the best experience on our website. Click here for more information.