- Home /
inventory script array lines?
i hit a wall! xD again -.- well i got 2 scripts atm. item.cs and inventory.cs i want the script to make 4 buttons, then a new line, 4 buttons new line and so forth. how do i do that? here is what i got this far:
ITEM
public bool isEquipped = false;
public int itemId;
public int buyPrice;
public int sellPrice;
public GameObject itemVisual;
public Texture2D icon;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//shows and hides item when equipped and unequipped
//if (isEquipped == true){
// itemVisual.renderer.enabled = true;
//}
//else itemVisual.renderer.enabled = false;
///////////////////////////////////////////////////
}
public void isEquippedCheck (){
if (isEquipped == true){
itemVisual.renderer.enabled = true;
}
else itemVisual.renderer.enabled = false;
}
}
inventory script here.
public GameObject[] itemSlots = new GameObject[10];
public int i = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI () {
Rect r = new Rect(0,0,35,35); // this is the Rect variable
for (i = 0; i < itemSlots.Length; i++){
if (GUI.Button(r,itemSlots[i].GetComponentInChildren<item>().icon)){
}
}
} }
Answer by Loius · Jun 28, 2012 at 06:04 PM
GUILayout.BeginArea( /* Rect in which the buttons will appear */ );
GUILayout.BeginVertical();
for ( int row = 0; row < rowMax; row++ ) {
GUILayout.BeginHorizontal();
for ( int button = 0; button < buttonMax; button++ ) {
GUILayout.Button( /* whatever goes here */ );
}
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
GUILayout.EndArea();
Note that I like to treat .Begin and .End as curlies for indentation purposes, makes it easy to see when I miss something.
Edit: Oops, edited to C#-style.
so where do i add this in? it look really confusing :/ sorry if im a total newbie
Your answer
Follow this Question
Related Questions
Click on a button that is created post start. 0 Answers
How to go around creating inventory with new GUI (4.6 Beta)? 1 Answer
How to start an inventory system? 2 Answers
multiple rows, in an array in C# 2 Answers
Mysterious crash involving an array 2 Answers