Game Development Reference
In-Depth Information
Function/method definitions
First of all, terminology in JavaScript uses the term Function , while C# calls these
Methods . They mean the same thing, and most C# coders understand the term Func-
tion .
JavaScript functions are declared with the function keyword before the function name.
C# method declarations just use the return type and the method name. The return type is of-
ten void for common Unity events. JavaScript functions are public by default, and you
can specify them as private , if required. C# methods are private by default, and you
can specify that they should be public , if required.
In JavaScript, you can omit the parameter types and the return type from the declaration,
but it's also possible to explicitly specify these (which is sometimes necessary if you run in-
to type ambiguity or problems):
// JavaScript user:
// a common Unity MonoBehaviour event handler:
function Start () { ...function body here... }
// a private function:
private function TakeDamage (amount) {
energy -= amount;
}
// a public function with a return type.
// the parameter type is "Transform", and the return type is
"int"
function GetHitPoint (hp : int) : int {
return (maxHp - hp);
}
// C# user:
// a common Unity monoBehaviour event handler:
Search WWH ::




Custom Search