Legacy Documentation: Version 5.1
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

GameObject.CompareTag

Switch to Manual
public function CompareTag(tag: string): bool;

Parameters

tag The tag to compare.

Description

Is this game object tagged with tag ?

	// Immediate death trigger.
	// Destroys any colliders that enter the trigger, if they are tagged player.
	function OnTriggerEnter (other : Collider) {
		if (other.gameObject.CompareTag ("Player")) {
			Destroy (other.gameObject);
		}
	}