- Home /
What could I put in function brackets?
I've been programming for a while. Now I want to know what could I put in function brackets. I don't know how to explain this so I can't search over google. Sometimes I used it when I needed but I don't quite understand it. So if anyone want to explain it to me, it would be great. For example:
function OnTriggerExit(other : Collider){
if (other.tag == "Name"){
//Do something}
}
Answer by rednax20 · Nov 25, 2013 at 09:23 PM
What you have up there is the real gist of it. you can use pretty much anything, i only know of a few exceptions. You could use public functions, private functions, variables, unity methods, your own methods, if statements, while loops, for loops, Unity variables, declare variables, change variables, instantiate, destroy, move, alter, and more!
OnTriggerEnter is what we call a generic functions,
http://docs.unity3d.com/Documentation/Manual/GenericFunctions.html
generic functions are unity built in things shall we say, they are run the code in there brackets when a certain thing happens in your game that would be hard to detect through just plain old codeing.
remember when i said there were a few exceptions, well you coroutines can get a little dodgy with some of the functions, and you cannot use a generic function within another generic function.
I'm sure that there are lots more exceptions but i can't think of anymore off the top of my head.
For an example of its usage, lets say you have a sword. You might use OnTriggerEnter() to tell when the sword has hit something.
The short answer is : Practically Anything.
hope this answered you question,
Quishtay™ all the way
Your answer
