Unity GameObject.CompareTag 用法
2017-12-31 本文已影响0人
醉杀楚天白
使用GameObject.CompareTag代替GameObject.tag:GameObject.tag会在内部循环调用对象分配的标签属性并分配额外的内存。
// When this game object intersects a collider with 'is trigger' checked,
// store a reference to that collider in a variable named 'other'..
void OnTriggerEnter(Collider other)
{
// ..and if the game object we intersect has the tag 'Pick Up' assigned to it..
if (other.gameObject.CompareTag ("Pick Up"))
{
// Make the other game object (the pick up) inactive, to make it disappear
other.gameObject.SetActive (false);
// Add one to the score variable 'count'
count = count + 1;
// Run the 'SetCountText()' function (see below)
SetCountText ();
}
}