C# How do you make this kind of script?

Hello All,

I am trying to make a script that has the ability to
define the size of a list in the inspector. And enables
and disables the MeshRenderer of a Plane by key press
that’s listed inside of that list.

At the moment I have another script without a
size list in the inspector working as intended by
having

public MeshRenderer mesh;
public MeshRenderer mesh1;

And so on, for the amount of planes that I have.
I have six planes attached to a parent. All planes
have been separted and formed into a cube.

As you can tell this would become time consuming
to do without a list in the future.

Please teach me how to do this, thank you.

public MeshRenderer[] mesh;

//or

public List<MeshRenderer> mesh;

Both a list and array can be set in the inspector.

If your script is being attached to the parent and there are no other meshrenderd in the object you can get them without having to manually set them in the inspector. Something like this.

private MeshRenderer[] meshs;
private void Awake()
{
  meshs = GetComponentsInChildren<MeshRenderer>();
}

You can then loop through this list and do what you need to do without having to manually set anything. Hope this helps.

-Alexander