Version: 1.4
LanguageEnglish
  • C#

Component.CompareTag

Declaration

public bool CompareTag(string tag);

Parameters

tag The tag to compare.

Returns

bool Returns true if GameObject has same tag. Returns false otherwise.

Description

Checks the GameObject's tag against the defined tag.

// Immediate death trigger.
// Destroys any colliders that enter the trigger, if they are tagged player.

using UnityEngine; using System.Collections;

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

对文档有任何疑问,请移步至开发者社区提问,我们将尽快为您解答