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 later in the code accepts float
, and we can't be bothered converting the int
values to the float
datatype. It's probably simpler and easier for them to begin their lives as floats anyway.
Earlier in our JavaScript code, we separated...