Spot the difference

This would be good to understand…?
-Sorry the capitalisation is hard to read, its easier to read not as code

function OnTriggerEnter (col: Collider){}

// vs

function OnTriggerEnter (Col: Collider){}

// capital C

function OnTriggerEnter (collider: Collider){}

//collider instead of col

function OnTriggerEnter (collision: Collision){}

//colision instead of Collision

function OnTriggerEnter (){}

//well nothing…?[/code]
Thank you very much… :idea:

The first four are the same. In JavaScript, the type of the variable follows the variable name. So here, the type is Collider and the name of the variable is whatever you like.

You just as easily have:

function OnTriggerEnter (MagicalPonies : Collider){}

Is this what you mean?

var MagicPonies : GameObject;
function OnTriggerEnter (MagicalPonies : Collider){
//MagicPonies.renderer.enabled = true;
}

So I could do this (as an example)?

Surely theyre not all the same…?

EDIT-Oh I get it-But what about the bottom2?
thanks
AC

To clarify, you don’t need the variable declaration in the first line. In JavaScript, anytime you see a “:” after a variable name you’re declaring a new variable. Function signatures just don’t use the “var” keyword, that’s the only difference.

So all you need is:

function OnTriggerEnter (MagicPonies : Collider) {
 MagicPonies.renderer.enabled = true;
}

What you’re saying there is that you’re declaring a new “MagicPonies” variable for use inside that function, of type Collider, and whatever’s calling that function will provide the data to fill the variable.

On the last function example in your original post–that’s basically the same function, except a version where the game engine doesn’t pass you the object that entered the trigger. You’d use that when you care that something has entered the trigger, but you don’t care which something.

Hope that helps!

Cool -Thanks
AC