- Home /
Multidimentional Array for Inventory style system in inspector.
Hey guys, I'm wanting to be able to create items from the inspector for my inventory. I'm not sure if I'll need to make an editor script or what but am open to all suggestion.
Basically all items will have a number of stats each with their own values. What I'm wanting is the ability to add another item to this multi-dim array from the inspector, which would then let me fill out the inside values.
In the end, I would hopefully be able to access each item in the array with something like
itemList[0][name];
itemList[0][damage];
I could paste some code of 3 public arrays which is my public system, but I think you can get the picture XD
Appreciate any input
Answer by whydoidoit · Jun 23, 2012 at 12:37 AM
So you don't really want to use a multi-dimensional array - you want to use an array of classes that means you won't have to write any inspector code too - which might be seen as a bonus.
using System;
...
[Serializable]
public class InventoryItem
{
public string Name;
public float Damange;
public bool someOtherProperty;
}
public List<InventoryItem> Items = new List<InventoryItem>();
Now you can use the inspector to create your list of items...
And you can access them like this:
Items[0].name etc...
No problem - just click the tick to mark it as answered and take it off the unsolved list :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613073148im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do I assign 3 variables to every GameObject in the array "enemy"? 2 Answers
Insert new custom class element with _default_ values to a SerializedProperty array? 1 Answer
Inspector Doesn't Update Array Elements When Updated In Array Constructor 1 Answer
Distribute terrain in zones 3 Answers
Why can't I access the Name field in the Custom Styles section of a GUISkin in the Inspector? 2 Answers