When I instantiate a say a monster in runtime, I need to access for example its NavMeshAgent and have to call GetComponent. Even if I have a script on the bugger to store all his components so I only have to make one GetComponent I still have to call at least once per, yes? Is there a better/faster way?
-
Find the object via a tag at runtime and then get it’s components? (example getting a script component)
private GameObject Monster1;
private Monster1Script monster1Script;
void Start()
{
Monster1 = GameObject.FindWithTag(“Monster1”)
// get the Monster1Script.cs component of the Monster1 GameObject
monster1Script = Monster1.GetComponent();
} -
If you are not using tags (or multiple monsters share the same tag) you would have to use public static GameObject Find(string name);