GameObject.FindGameObjectsWithTag 查找标签的游戏物体列表
static function FindGameObjectsWithTag (tag : string) : GameObject[]
Description描述
Returns a list of active GameObjects tagged tag. Returns null if no GameObject was found.
Tags must be declared in the tag manager before using them.
返回一个用tag做标识的活动的游戏物体的列表.如果没有找到则为空。
标签必须在使用之前到标签管理器里面声明。
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public GameObject respawnPrefab;
public GameObject[] respawns = GameObject.FindGameObjectsWithTag("Respawn");
public void Awake() {
foreach (GameObject respawn in respawns) {
Instantiate(respawnPrefab, respawn.transform.position, respawn.transform.rotation);
}
}
}
// Instantiates respawnPrefab at the location
// of all game objects tagged