C# addendum
As promised, the complete translated C# code for the Tic Tac Toe game follows. There were a few tricky spots in the code that required a bit of tap dancing:
When a function returns a value, the value type needs to be declared in the function signature before the function name. So this function declaration in Unity Javascript:
function CheckForWin(square:GameObject):boolean
is translated like this in C#:
private bool CheckForWin(GameObject square)
In an earlier chapter, we dodged the requirements of the waitForSeconds
method and used a different function entirely. Now that we've had more experience with return statements, we can discuss what's required.
In C#, this line:
yield WaitForSeconds(3);
becomes:
yield return new WaitForSeconds(3); ...
Get Unity 4.x Game Development by Example Beginner's Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.