If I have 20 of the same game object in the scene but it can be in different states, what is the best way to find objects based on the current state?
For example my current stat is something like:
I have 20 game objects named “business” and each business maybe be a type (10 options) and either running or not running.
Right now I have the business change its tag to “lumbermill is running” and on my character I findgameobjectwithtag to create an array of all of the current lumbermills that are running.
This method is working but as I keep increasing the business types I’m dealing with alot of tags. I really don’t want to make each one an individual game object. Is there a better way?
Make a MonoBehaviour to identify them and use FindObjectsOfType() to find them all.
Ideally only use that finder function once, at start of level, or perhaps when you know one was added / removed, eg, ideally not every single Update() loop.
You could also do it with an interface, which you would implement in a MonoBehaviours.
Using Interfaces in Unity3D:
Check Youtube for other tutorials about interfaces and working in Unity3D. It’s a pretty powerful combination.