GameObject.FindWithTag 查找标签

static function FindWithTag (tag : string) : GameObject

Description描述

Returns one active GameObject 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 respawn = GameObject.FindWithTag("Respawn");
	public void Awake() {
		Instantiate(respawnPrefab, respawn.transform.position, respawn.transform.rotation);
	}
}
//在标签为"Respawn"的游戏物体的位置实例化一个respawnPrefab.

var respawnPrefab : GameObject;
var respawn = GameObject.FindWithTag ("Respawn");
Instantiate (respawnPrefab, respawn.transform.position, respawn.transform.rotation);
Page last updated: 2011-5-19