noob question re: variable

Hey All,
Im working on a tutorial that has this simple OnTriggerEnter script - as follows


function OnTriggerEnter (myTrigger : Collider) {

if(myTrigger.gameObject.name == “box”){

Debug.Log(“Box went through!”);

}

}


my question is:
Does this Function initialize a variable “myTrigger:Collider”
by placing it in the parentheses?

if so, can I do this all the time (create variables on the fly by placing them in function parentheses)?

thanks for any help.

It’s an argument, a value you pass to a function. The function has to be written to accept arguments.

If you’re new to scripting, I recommend reading this:

http://forum.unity3d.com/viewtopic.php?t=36096

Thanks for the reply
Question:
I understand it is a argument that I’m passing to the function.
but, it in a way, dosen’t (myTrigger) becomes a temporary variable because it now is = to “box” the collider that has been hit,
yes? - or no?
-am I over thinking it?
thanks for any help.

Yeah, you can think of “myTrigger” being a special temporary variable that’s declared for the scope of that method. The only difference is it is assigned a value by whatever calls that method.

If you want to create other variables for use in that method, but not expose them as an input parameter for the method, just declare them on their own line below the method signature:

function OnTriggerEnter (myTrigger : Collider) 
{
	var someOtherVariable : String = "asdf";
	var anotherOne : int = 5;
}

Great!
That makes sense.
Thanks for taking the time to explain.
J.