Using tags with OnTriggerEnter

To begin: I’m not entirely clear on the parameters for the OnTriggerEnter function. What exactly are other and Collider referring to?

So here’s what I’m trying to accomplish:

function OnTriggerEnter (other : Collider) {
	if (other == GameObject.FindWithTag("P1").GetComponent(Collider)){
		running = false;
   }
}

that doesn’t seem to work… I’ve also tried:

function OnTriggerEnter (other : Collider) {
   if (other.GameObject.tag == ("P1")
      running = false;
}

The collider on P1 is a capsule collider and the trigger is a standard box collider with isTrigger enabled.

Any ideas?

The OnTriggerEnter function receives one parameter: The Collider the trigger collided with i.e. the other collider in the trigger collision besides the trigger.

I don’t see at the first glance why the first example doesn’t work but the second one is the way I would go. Comparing Collider objects doesn’t seem like a very clean solution to me.

Looking at the second example, I spot two errors:

  • There’s a unmatched “(” in the if.
  • GameObject is the class while gameObject is the variable name. Capitalization is important.
function OnTriggerEnter (other : Collider) {
   if (other.gameObject.tag == "P1")
      running = false;
}

Sorry, the unmatched ) was a typo in my post. Although the gameObject vs. GameObject was very helpful!

I figured out my biggest problem. The script was attached to the wrong object! DOH

Thanks for the help!!