GameObject.FindWithTag 查找标签

static function FindWithTag (tag : string) : GameObject


Returns one active GameObject tagged tag. Returns null if no GameObject was found.
Tags must be declared in the tag manager before using them.


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

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