0

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.

1
  • 2
    well wrap them in a type ... [Serializable] public class ValuePair { public GameObject item; public int quantity; } and then public ValuePair[] requirements; => tadaaa? ... maybe worth looking some very basic tutorials about c# in general first? ;) Commented Aug 23, 2022 at 14:20

1 Answer 1

2

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.