I'm using a "toggle visibility" script on many objects in my scene, and in my gameController
class I'm storing references to them in an array like this:
public Fields[] fields;
then I access them by the array index:
fields[0].setVisibility(true);
This works fine, but this list is growing and everything is getting unmaintainable.
So I would like to iterate thru the references to the objects, find the script by its game object name, and call the required function setVisibility(state)
.
A call, if possible should look like this:
GameObjectName.ScriptName.FunctionCall.State
In this way, I would have a clear overview of my code.
Is this possible in Unity C#?
Fields
a MonoBehaviour? How would one determine "the required function" using the game object's name? The more context you can give us about what gameplay feature you're implementing here, the better we can target answers that will be effective and scalable for that use. (Name-based lookups make me wary — there are almost always better solutions available) \$\endgroup\$