- Home /
Array in Arrays (Item info type)
Hi!
I'm making a simple game which I use some kind of shop mechanism in. I want to have icons, price and quantity. I've done this before but it was very messy in the inspector. So what I need is like an array of arrays of items. In there I need to store the name of the item, the icon of the item, the price and the quantity of the item.
Do someone know how to do this? If you do, please tell me!
Thanks
Answer by fafase · May 03, 2014 at 12:25 PM
I am not sure I fully understand the point of an array of arrays but more likely an array of objects:
[System.Serializable]
public class Item{
public Texture2D icon;
public float price;
public int quantity;
}
then in your class:
public class Inventory:MonoBehaviour{
public Item[] items;
}
This will show up in your inspector and you can add value to the size and drag and drop texture and give values to price and quantity.
A bit more explanation on what I mean. I'm making a kind of cookie clicker game. So I need a shop. And the shop needs to be fancy. So, ins$$anonymous$$d of doing like item1Icon, item2Icon, item1Price e.t.c for different items, I can have a fancy menu so I simply create items, give them a icon, price and save the quantity. Then I can simply assign them to buttons so you can buy them. That is what I mean. Also, I tried your code but it doesn't show up in the inspector.
EDIT: Never$$anonymous$$d. Got it work. Thanks for the help!
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Make the audio manager select from an array of sounds 1 Answer
List all children in array? 5 Answers
Preventing Items from shifting in a list 1 Answer
List changes affecting Array 2 Answers