OnTriggerEnter with variable

I’m trying to create a code that accesses an external collider but all I’m getting is "The name does not denote a valid type (not found).

var colliding : Collider;

function OnTriggerEnter (collider : colliding) {

What am I doing wrong?

You’re using the C# format, where the type is listed first and not second. Here’s a UnityScript version below.

function OnTriggerEnter (colliderName : Collider) {
		Destroy(other.gameObject);
	}

Here you can see the Collider type is denoted second, while the name you specify for the collider is first. You don’t need to create a variable for the collider either, as it’s handled in-function as a local variable.

Here is the API for the collider class as well, for more usage.

I’m guessing, you need to access a collider outside of the trigger event? If so, you can do this:

#pragma strict

var externalCollider : Collider;

function OnTriggerEnter( col : Collider )
{
	externalCollider = col;
}

Now that you have a reference, you can use the collider from the event for anything you need. Hope this helped…