GameObject.CompareTag 比较标签

function CompareTag (tag : string) : bool

Description描述

Is this game object tagged with tag?
这个游戏物体是否被标识tag标签?

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	void OnTriggerEnter(Collider other) {
		if (other.gameObject.CompareTag("Player"))
			Destroy(other.gameObject);

	}
}
// Immediate death trigger.
// Destroys any colliders that enter the trigger, if they are tagged player.
// 立即销毁trigger的游戏物体.
// 如果一切进入这个trigger的碰撞体被标识了,则销毁它.

function OnTriggerEnter (other : Collider) {
	if (other.gameObject.CompareTag ("Player")) {
		Destroy (other.gameObject);
	}
}
Page last updated: 2010-12-13