代码演示:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FindObjectOfType : MonoBehaviour {
private GameObject[] things;
private GameObject thing;
void Start () {
things = FindObjectsOfType<GameObject>();
thing = FindObjectOfType<GameObject>();
Debug.Log("第一个" + thing.name);
for(int i = 0; i < things.Length; i++)
{
Debug.Log(things[i].name);
}
}
}
---------------------