I’m setting up my enemies to be spawned into existence when the player triggers particular scripts, typically by touching some trigger volume. But I’m also setting up some enemies that are going to depend upon specific paths set into the level. This means I need a way for those enemies to be able to find what path they need to associate with autonomously, as I can’t just drop a reference in the inspector for a object that was just instantiated into the scene.
I’m open to suggestions as to how I could do this.
I’m thinking it could work simply enough if I place the spawn-point close to a node on the path, and then the enemy can just look for path nodes near it. But how?
I couldn’t use colliders and triggers for this, at least not without making something convoluted. There are no colliders on the path nodes, and if I tried to add trigger colliders to the path node, well, triggers can’t collide with triggers.
Is there some kind of universal function to search for gameObjects within a given area?
So I could, say, search for all game objects within a sphere around the enemy, and then iterate through those objects until I find one with a specfic script on it, or maybe a custom tag. If I set it to search within say a 1 unit sphere, there shouldn’t be more than a couple objects to iterate through, (especially if I could ignore the object the script is attached to.)