Game Development Reference
In-Depth Information
Color
R
:
0
,
G
:
0
,
B
:
0
,
A
:
255
, (black color)
5. Next, we will create the script to control our
RocketUI
object. Let's go to
Assets
|
Create
|
Javascript
(for Unity JavaScript users) or
Assets
|
Create
|
C#
(for C#
users), name it
RocketUI
, double-click on it to launch
MonoDevelop
, and
define the variables as follows:
// Unity JavaScript user:
#pragma strict
private var _guiTexts : GUIText[];
function Awake () {
_guiTexts = GetComponentsInChildren.<GUIText>();
}
function UpdateUI ( ammo : int ) {
for (var i : int = 0; i < _guiTexts.Length; ++i) {
_guiTexts[i].text = ammo.ToString();
}
}
// C# user:
using UnityEngine;
using System.Collections;
public class RocketUI : MonoBehaviour {
GUIText[] _guiTexts;
void Awake () {
_guiTexts = GetComponentsInChildren<GUIText>();
}
public void UpdateUI ( int ammo ) {
for (int i = 0; i < _guiTexts.Length; ++i) {