C# Addendum

The ClockScript was fairly painless to convert to C#. These were the steps:

  1. Copy/paste the JavaScript code into a new C# script (keeping the C# class definition and omitting the #pragma strict line)
  2. Add the appropriate access modifier to the variable definitions (note: any variables that need to show up in the drag-n-drop Unity interface, like the ones that store the textures, need the public modifier. Use private for all other variables)
  3. Change the syntax of all the variable definitions (declare the type before the variable name, and nix the colon)
  4. Change the function declarations so that they start with the return type (void in all cases for this script) and an access modifier (private for all of these functions)
  5. Add the new keyword when ...

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.