Game Development Reference
In-Depth Information
Note
final : We use the word final here because we want the value to be assigned
only once. We can say that this is the constant value and it is used to prevent the
error from reassigning the value.
// C# user:
using UnityEngine;
using System.Collections;
public class Menu : MonoBehaviour {
public enum TAB {STATUS,INVENTORY,EQUIPMENT};
public GUISkin customSkin;
public Texture heroTexture;
public Texture statBox1Texture;
public Texture statBox2Texture;
public Texture skillBoxTexture;
readonly string[] TOOLBARS =
{TAB.STATUS.ToString(),
TAB.INVENTORY.ToString(),TAB.EQUIPMENT.ToString()};
readonly Rect HERO_RECT = new Rect (19, 35, 225,
441);
readonly Rect CLOSE_BTN_RECT = new Rect (598, 8,
26, 22);
readonly Rect TAB_BTN_RECT = new Rect (35, 15, 480,
40);
TAB _currentTool = TAB.STATUS;
Rect _windowRect = new Rect (10, 10, 640, 480);
bool _isMenuOpen = false;
}
Note
readonly : We use readonly instead of const here because string[] and
Rect aren't the constant expressions in C# and are not known at the compile
time. So, it will produce a compile error if we use const . Also, readonly is
basically similar to the word final in Java, which can be initialized only once.
Search WWH ::




Custom Search