Game Development Reference
In-Depth Information
6. Next, we will start the irst funcion with the ShowWeapon() funcion, which will
display the weapon selecion box; type the following code:
private function ShowWeapon () : void {
var in_items : int = 6;
var itemsContent : GUIContent[] = new GUIContent[in_items];
//We create a GUIContent array of key item here (if you have
more than 1 item, you can also use your item array instead of the
current item)
for (var i: int = 0; i < in_items; i++) {
if (i == 0) {
itemsContent[i] = GUIContent(s_unequip, "");
} else {
itemsContent[i] = GUIContent(a_weapons[0].name, a_
weapons[0].icon);
}
}
scrollPosition3 = GUI.BeginScrollView (new Rect (257, 300, 320,
120), scrollPosition3, new Rect (0, 0, 280, 40*in_items));
//We create grid button here.
in_toolWeapons = GUI.SelectionGrid (Rect (0, 0, 280,
40*in_items), in_toolWeapons, itemsContent, 1, GUI.skin.
GetStyle("Selected Item"));
//End the scrollview we began above.
GUI.EndScrollView ();
gui_weaponCon = itemsContent[in_toolWeapons];
}
7. Then, we will create the ShowArmor() funcion, which will be used to display the
armor box as follows:
private function ShowArmor () : void {
var in_items : int = 6;
var itemsContent : GUIContent[] = new GUIContent[in_items];
//We create a GUIContent array of key item here (if you have
more than 1 item, you can also use your item array instead of the
current item)
for (var i: int = 0; i < in_items; i++) {
if (i == 0) {
itemsContent[i] = GUIContent(s_unequip, "");
} else {
itemsContent[i] = GUIContent(a_armors[0].name, a_
armors[0].icon);
}
}
 
Search WWH ::




Custom Search