frob
frob

Reputation: 11

unity c# - how to get multiple things in one element of an array

I want to make an array that looks like this image but cannot work out how to get for example a gameobject and an int into one element of an array.

Upvotes: 0

Views: 614

Answers (1)

Sisus
Sisus

Reputation: 729

You can do this by defining a custom class or struct containing multiple serialized fields and adding the Serializable attribute to it.

[Serializable]
public class ElementData
{
    public GameObject gameObject;
    public int amount;
}

Then you can define an array of this custom class.

public ElementData[] array;

Upvotes: 2

Related Questions