- Home /
Populate inventory with item icons
Hello everyone. I have my inventory window setup the way I want, but right now it only displays the number of the slot. I've been using a mish mash of tutorials that explain how to populate the inventory with random items from chests etc but I have a set number of items I need to place in the inventory. How can I get the item icons to show up in the slots?
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class MyGUI : MonoBehaviour {
public GUISkin mySkin;
public float lootWindowHeight;
public float buttonWidth = 40;
public float buttonHeight = 40;
private float _offset = 10;
/********************************************************/
/* Inventory Window Variables*/
/********************************************************/
private bool _displayInventory = true;
private const int INVENTORY_WINDOW_ID = 1;
private Rect _inventoryWindowRect= new Rect(10,10,170,265);
private int _inventoryRows = 6;
private int _inventoryCols = 4;
private const string ARMY_MEN_PATH = "Item Icons/Army Men";
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnGUI(){
_inventoryWindowRect = GUI.Window(INVENTORY_WINDOW_ID, _inventoryWindowRect,InventoryWindow, "Inventory");
}
public void InventoryWindow(int id){
int cnt = 0;
for(int y = 0;y < _inventoryRows;y++){
for(int x = 0;x < _inventoryCols;x++){
GUI.Button(new Rect(5 + (x * buttonWidth),20 + (y * buttonHeight),buttonWidth, buttonHeight),(x + y * _inventoryCols).ToString());
GUI.Button(new Rect(5 + (x * buttonWidth),20 + (y * buttonHeight),buttonWidth, buttonHeight),(x + y * _inventoryCols).ToString(),"box");
cnt++;
}
}
GUI.DragWindow();
}
public void ToggleInventory(){
}
}
Hey, here is a tutorial, that show you how to create an inventory with the most common operations. https://www.youtube.com/watch?v=$$anonymous$$LaGkc87dDQ it also explains you how to populate the inventory with icons
Answer by Epsilon Naught · Nov 13, 2012 at 01:03 AM
http://www.burgzergarcade.com/tutorials/game-engines/unity3d/132-unity3d-tutorial-item-icons
Hopefully helps!
Your answer
Follow this Question
Related Questions
Inventory SlotID vs. RectPosition 0 Answers
GUI error with texture. 1 Answer
Screen.width and Screen.height does not cover screen. Why? 4 Answers
Inventory Help 0 Answers
How to select a texture in an inventory? 0 Answers