Function/method definitions

First of all, terminology—JavaScript uses the term function, while C# calls these methods. They mean the same thing, and most C# coders understand the term function.

JavaScript functions are declared with the keyword function before the function name. C# method declarations just use the return type, and the method name. The return type is often 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 into ype ambiguity problems).

JavaScript:

// 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#:

// a common Unity monobehaviour event handler: 
void Start() { ...function body here... }  

// a private function: 
void TakeDamage(int amount) {     
energy -= amount; 
}  

// a public function with a return type. 
// the parameter type is "Transform", and the return type is "int" 

public int GetHitPoint (int hp) {     
  return (maxHp—hp); 
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.73.207