I whould like to make an 2D array visible in the inspector so I can drag GameObjects in it(go#) and write a float value (relatieveFactor#) so I can use those later in the script.
It should look like I show you below, but I ceep failing. I think I mix all the information a searched on the web.
[System.Serializable]
public class Objecten
{
public GameObject element;
public float relatieveFactor;
}
public class CubeMaker : MonoBehaviour {
public Objecten[,] parts = new Objecten[GameObject ,float 1.0]; //default float = 1.0
...
Or do I need to use get and set for it?
I hope you can help me and thanks for your time.
public Objecten[,] parts =new Objecten[GameObject ,float1.0];
THAT is NOT how you create an array.
I think you mean to have a one dimensional of a data structure that is made up of 2 distinct values. One typed GameObject, one typed float.
Try something like this:
public class CubeMaker : MonoBehaviour
{
public Objecten[] parts;
}
Objecten defines the two values for you, the array is just of those Objectens.
Note, you’d set the default value for ‘relativeFactor’ in the class its in, but just as I brought in this other thread:
default values don’t work for array elements as you might expect… it’s just the way the serializer works. So you’re not going to get to default the factor to 1f quite the way you want.