Game Development Reference
In-Depth Information
However, if we want to wait for the user input in C#, which might be over several frames, we
will have to use StartCoroutine . In JavaScript, the compilers will automaically do it for us.
JavaScript:
yield WaitForMyFunction(5);
//This is similar with
yield StartCoroutine(WaitForMyFunction(5));
function WaitForMyFunction(waitTime : float) {…}
//coroutine function
C#:
//Need to put StartCoroutine
yield return StartCoroutine(WaitForMyFunction(5));
IEnumerator WaitForMyFunction(waitTime : float) {…}
//coroutine function
Casting
JavaScript automaically casts from one type to another, wherever possible. For example, the
Instantiate command returns a type of Object :
JavaScript:
//There's no need to cast the result of "Instantiate" provided the
variable's type is declared.
var newObject : GameObject = Instantiate(sourceObject);
C#:
// in C#, both the variable and the result of instantiate must be
declared.
// C# first version
GameObject foo = (GameObject) Instantiate(sourceObject);
// C# second version
GameObject foo = Instantiate(sourceObject) as GameObject;
 
Search WWH ::




Custom Search