Game Development Reference
In-Depth Information
The new keyword
In JavaScript, you can create a new instance of an object or struct without using the new
keyword. In C#, using new is mandatory.
JavaScript:
var myPosition = Vector3(0,0,0);
var myInstance = MyClass();
//We can also use new keyword in JavaScript
var myInstance = new MyClass();
C#:
Vector3 myPosition = new Vector3(0,0,0);
MyClass myInstance = new MyClass();
YieldInstruction and coroutine
There are differences in the syntax of C# and JavaScript as follows:
JavaScript:
yield WaitForSeconds(3); //pauses for 3 seconds
yield WaitForMyFunction(); //start coroutine
function WaitForMyFunction() {…} //coroutine function
C#:
yield return new WaitForSeconds(3); //pauses for 3 seconds
yield return WaitForMyFunction(); //start coroutine
IEnumerator WaitForMyFunction() {…} //coroutine function
In JavaScript, it will automaically generate the return type to
IEnumerator if you put yield instrucion inside the funcion. On the
other hand, in C# you will need to specify the return type to IEnumerator .
 
Search WWH ::




Custom Search