Game Development Reference
In-Depth Information
Changing Struct properties by value
VS by reference
Structures are passed by value in C#, so you cannot change the x or y value of a Vector3
and you need to create a new Vector3 and assign it to the Vector3 that you want.
However, in JavaScript, you can write it as follows.
JavaScript:
transform.position.x = 1;
C#:
transform.position = new Vector3(1, transform.position.y, transform.
position.z);
Function/method definitions
First of all, terminology - JavaScript uses the term funcion, while C# calls these methods.
They mean the same thing, and most C# coders understand the term funcion.
JavaScript funcions are declared with the keyword function before the funcion name. C#
method declaraions just use the return type, and the method name. The return type is oten
void for common Unity events. JavaScript funcions 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 declaraion,
but it's also possible to explicitly specify these (which is someimes necessary if you run into
type 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"
 
Search WWH ::




Custom Search