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);


 yield return new WaitForSeconds(3); ...

Get Unity 4.x Game Development by Example Beginner's Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.