C# addendum

Converting the TitleGUI JavaScript to C# was pretty painless:

using UnityEngine;
using System.Collections;

public class TitleGUICSharp : MonoBehaviour {
private float buttonW = 100; // button width
private float buttonH = 50;  // button height
private float halfScreenW; // half of the Screen width
private float halfButtonW; // half of the button width

public GUISkin customSkin;
private void Start()
{
  halfScreenW = Screen.width/2;
  halfButtonW = buttonW/2;
}
private void OnGUI ()
{
 GUI.skin = customSkin;
  if(GUI.Button(new Rect(halfScreenW-halfButtonW, 460,
     buttonW, buttonH), "Play Game"))
  {
      Application.LoadLevel("game");
  }
}
}

Here are the changes:

We declared buttonW and buttonH as floats instead of ints, because the Rect structure ...

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.