Arrays with multiple data types C#
So I've heard this trick is pretty great at just handling data storage. And I wanna learn how to use it, but a few things I'm fuzzy on.
I've read this answer, http://answers.unity3d.com/questions/698312/store-multiple-types-of-data-in-an-array.html but unfortunately I'm still learning C# and there are some things I'm fuzzy on. If I create a class;
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class ButtonData : MonoBehaviour
{
public GameObject buttonGameObject;
public Image buttonImage;
public Button button;
public float coolDown;
public int value;
}
And then I call that class to create an array within another class;
public ButtonData[] allButtonData;
How come if I remove : MonoBehavior from the ButtonData class, the array of buttonData [] disappears in the inspector?
And where do I fill in the values of each entry? It can't be done within the inspector as that only seems to be looking for objects containing that class?
I guess I was sort of expecting a means to house data and then enter that data in the inspector like you can with any other single data type array.
So if anyone knows of a great tutorial page or documentation as to how and coders use this method, I'd love to read it.
Answer by instruct9r · Jan 16, 2016 at 09:32 PM
You have to serialize the Class.
So above the class declaration type:
[System.Serializable]
And you can remove the MonoBehaviour inheritance. You can just leave it as class, that doesn't inherit from anything.
Now you can declare an instance of that class in a MonoBehaviour script...
If i understand correctly your question..
Your answer
Follow this Question
Related Questions
Managing In-Game Variables of Different Data Types 1 Answer
Null reference exception in an if statement that checks for it. 1 Answer
I have an array from which spawns a random image. Instantiate spawning full pool on start 1 Answer
Using a class to control two "player" objects 1 Answer
Game Manager can't decide what the instance of the object is despite just making an instance of it 1 Answer