- Home /
Question by
Theacesofspades · Feb 18, 2013 at 05:10 AM ·
javascriptarraysinventoryclasses
Inventory Help.
So i am making an inventory (well attempting), and i need some help on what to do next. I have an inventory box that pops up that is made of buttons, then i have an array that i can add things to, but where do i go from here? Here are my scripts:
Inventory Script:
var Inventory = new Array ();
var emptySlot : Texture;
var showInventory = false;
var ex1 : float = 2.8;
var why1 : float = 5.8;
var exBig : float = 200;
var whyBig : float = 200;
var ex2 : float = 2.8;
var why2 : float = 5.8;
function Update ()
{
Debug.Log(Inventory.length);
}
function OnGUI ()
{
if (GUI.Button(Rect(Screen.width-100, Screen.height/2-50, 100, 100), emptySlot))
{
if (!showInventory)
{
showInventory = true;
}else{
showInventory = false;
}
}
if (showInventory)
{
GUI.Box(Rect(Screen.width/ex1, Screen.height/why1, exBig, whyBig), "Inventory");
for (var x=1; x<6; x++)
{
for (var y=1; y<6; y++)
{
if (GUI.Button(Rect(Screen.width/ex2+x*50, Screen.height/why2+y*50, 50, 50), emptySlot))
{
}
}
}
}
}
Add Item Script:
var inventoryObject : Transform;
function Item ()
{
var name : String;
var description : String;
var myIcon : Texture;
}
function Update ()
{
if (Input.GetKeyDown("e"))
{
inventoryObject.GetComponent(Inventory).Inventory.Add(Item);
}
}
Where do i go from here? And can you tell me if im going in the right direction. Thanks!
Comment
Answer by Bincredible · Feb 19, 2013 at 10:45 PM
I am not too experienced with Inventory's but to me that looks like a good start! :) and from there. It depends on what you want to do with it next.
Answer by MileSplit · Mar 05, 2013 at 10:59 PM
Hey i made a (noobish) inventory and this tutorial helped A TON
http://www.youtube.com/watch?v=QlF6t5gI5es
i think its tutorals 31-34