I have a for loop that makes buttons in a crate. I need it to be so that when the for loop makes 3 buttons, the buttons begin to start on the next row using the variable buttonHeight * cnt to control how far down they go. Can anyone help me out here?
Heres the script.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class OpenCrateScript : MonoBehaviour
{
static public bool lootCrateOpen = false;
public float maxDistance;
public Texture2D CrateWindow;
public GUIStyle CrateSlotStyle;
public GUIStyle CrateButtons;
private List<Item> lootItems;
private int buttonWidth = 78;
private int buttonHeight = 78;
void Start ()
{
maxDistance = 2.0f;
lootItems = new List<Item> ();
Populate ();
}
void Update ()
{
if (craftingMenu.craftingMenuOn == true || BuildingMenu.buildingMenuOn == true)
{
lootCrateOpen = false;
}
if (Input.GetKeyUp(KeyCode.E) && lootCrateOpen == false) {
RaycastHit hit;
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit)) {
if (hit.collider.CompareTag("Loot Crate") && Vector3.Distance(hit.collider.transform.position, transform.position) <= maxDistance) {
lootCrateOpen = true;
}
}
}
else if (Input.GetKeyUp(KeyCode.E) && lootCrateOpen == true)
{
lootCrateOpen = false;
inventorySystem.inventoryOn = false;
inventorySystem.toolbarOn = false;
}
if (inventorySystem.inventoryOn == true && Input.GetKeyUp (KeyCode.E))
{
lootCrateOpen = false;
}
}
void OnGUI()
{
if (lootCrateOpen == true)
{
GUI.BeginGroup(new Rect(760,30,600,750), CrateWindow);
for(int cnt = 0; cnt < lootItems.Count; cnt++)
{
GUI.Button (new Rect(buttonWidth * cnt,78,buttonWidth,buttonHeight),cnt.ToString(),CrateSlotStyle);
}
GUI.EndGroup();
inventorySystem.inventoryOn = true;
inventorySystem.toolbarOn = true;
}
}
void OnMouseEnter()
{
}
private void Populate()
{
for (int cnt = 0; cnt < 25; cnt++)
{
lootItems.Add (new Item());
}
}
}
Tell me if you need more information! And thanks for any help.