- Home /
Spell and Item arrays...
I am working on a platformer for mobile devices, and I came across a difficulty... How am I to record items in an array, display them in an item menu, and instantiate the sprite when clicked? I am fairly new to c# in unity, so I need assistance. Thanks in advance!
Answer by sparkzbarca · Jul 22, 2013 at 01:49 PM
create an item class with a sprite gameobject as the variable then spawn it as part of the Inventory class
something like
Item : MonoBehavior
{
public GameObject Sprite; //assign sprite through the editor
}
Inventory : MonoBehavior
{
List<Item> MyItems;
//now put an item in the list somehow for example
//for this you'd want to do a raycast to find someone clicking on an item on the ground
//if it is an item you'd call this function on it.
bool PickUpItem(Item itemOnGround)
{
MyItems.add(itemOnGround)
return true;
}
now display them
bool DisplayInventory()
{
foreach (Item item in MyItems)
{
instantiate(item.sprite,spawnposition,spawnrotation);
}
return true;
}
}
thats a VERY BASIC example of a class and how it might work and interact.
I am a bit confused myself... this is in Javascript, correct?
And another thing, how would I implement this in a GUI function? Can you refer me to tutorials if possible?
BurgZergArcade series, linking to Inventory scan all his for help with a particular area.