- Home /
Question by
Bincredible · Oct 16, 2013 at 04:26 PM ·
arrayinventoryscrollviewfor-loop
Inventory Help.
Hey, I started an inventory system that works fine, but when I add a scroll view seen as it's in the for loop it is multiplying the scroll view each time an item is added to the list. Here is my code, the for loop is on line 59. Any help would be appreciated!
import System.Collections.Generic;
var items : Item[];
var inventoryItems : List.<Item> = new List.<Item>();
var equipMenu : Item[];
var inventoryOpen : boolean;
var inventoryOpenClose : String;
var scrollPosition : Vector2 = Vector2.zero;
var Description;
function Start () {
}
function Update(){
if(inventoryOpen){
inventoryOpenClose = "Close Inventory";
}else{
inventoryOpenClose = "Show Inventory";
}
if(Input.GetButtonDown("Inventory")){
inventoryOpen = !inventoryOpen;
}
}
function OnTriggerEnter(other : Collider){
if(other.tag == "HealthKit"){
inventoryItems.Add(items[1]);
Destroy(other.gameObject);
}
if(other.tag == "Cookie"){
inventoryItems.Add(items[0]);
Destroy(other.gameObject);
}
}
function OnGUI(){
if(GUI.Button(Rect(1,571,120,26),inventoryOpenClose)){
inventoryOpen = !inventoryOpen;
}
if(inventoryOpen){
GUI.Box(Rect(1,309,160,260),"Inventory");
GUI.Box(Rect(6,495,150,70),"");
GUI.Label(Rect(8,494,150,70),"Item Description :");
GUI.Label(Rect(8,514,150,70),Description);
for(var x = 0; x < inventoryItems.Count; x ++){
scrollPosition = GUI.BeginScrollView (Rect (7,340,150,118), scrollPosition, Rect (0, 0, 0, 200));
if(GUI.Button(Rect(0,0 + (60 * x), 58,58),inventoryItems[x].icon)){
}
GUI.EndScrollView ();
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Inventory system using an array... 3 Answers
Array Overflow Problem 1 Answer
A node in a childnode? 1 Answer
Writing certain values of an array into a different array 3 Answers
Scroll List Problem 1 Answer