数组

Tutorial

Beginner

+0XP

5 mins

132

Unity Technologies

数组

使用数组将变量集合在一起以便于管理。

本教程包含在“初级编程”项目中。

上一教程:Instantiate

下一教程:Invoke

Languages available:

1. 数组

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);
        }
    }
}

Complete this Tutorial