- Home /
Question by
TrewSx · Mar 13, 2013 at 09:23 PM ·
javascriptguiarrayitem
Array of random loot items inside GUI.window
Hello, i would like to create a GUI.Window which will generate random loot from an Array of items. So far i got the window working but i am struggling with generating the random loot and displaying my GUI.Buttons inside GUI.window. Could anyone pls help me to solve this problem or at least tell me what is wrong here
#pragma strict
//Loot window script
//Inspector variables
public var buttonWidth : float = 40;
public var buttonHeight : float = 40;
//Loot variables
public var lootWindowHeight : float = 90;
public var itemsListArray : Array = [1,2,3,4,5,6,7,8,9,10];
private var _lootWindowRect : Rect = new Rect(0,0,0,0);
private static var _lootWindowID : int = 1; //ID number has to be Unique for each window
private static var _cnt : int = 0; //counter valoue for FOR LOOP
private var _lootWindowOffSet : int = 10;
function Start () {
//Debug.Log("Array items: " + itemsListArray);
itemsListArray = new Array (itemsListArray);
Populate();
}
function OnGUI() {
_lootWindowRect = GUI.Window(_lootWindowID, new Rect(_lootWindowOffSet, Screen.height - (_lootWindowOffSet + lootWindowHeight), //Display Loot window on a screen
Screen.width - (_lootWindowOffSet * 2),lootWindowHeight), LootWindow, "Loot Window");
}
private function LootWindow(_lootWindowID) {
for(; _cnt < itemsListArray.Count; _cnt++) {
GUI.Button(new Rect(buttonWidth * _cnt, buttonHeight * _cnt, buttonWidth, buttonHeight), _cnt.ToString());
}
}
private function Populate() {
for(; _cnt < 10; _cnt++) {
itemsListArray.Add(new Array(_cnt));
//Debug.Log(_cnt + " -- " + itemsListArray);
}
}
Comment
I think I'm having the same problem you are having. Did you figure it out? I can't seem to generate buttons with a for loop.
Your answer
Follow this Question
Related Questions
Setting up an array of Items 1 Answer
Can't add GameObjects to ArrayList 1 Answer
Enum ToString via Int (JS) 2 Answers
How can i find Next and Previous Child ? 1 Answer
[SOLVED] First array slot blocking second array slot 1 Answer