How to get a particular instance of a prefab enemy to follow the player?
The scene has a terrain and a fps controller. As soon as the player enters an invisible sphere, enemies start spawning. Now, the enemy (navmeshagent) prefab has a sphere child object which is a trigger and as and when player enters it, the enemy starts chasing the player. The problem is, the scene contains multiple instances of enemies at different locations, however, if the player is detected by a single instance of enemy prefab, all the instances of the enemy prefab in the scene start chasing the player along with the one who detected the player. How can I get that particular instance(the one that detected the player) only to chase the player while the other instances do nothing until they detect the player?
Enemy controller is attach one by one to enemy object or only one enemies controller all enemies gameobject?
Enemy is a prefab which is being spawned as and when the player enters a specific area. And so all the enemies are being controlled by a single navmesh script.
you should add another script to one by one enemy, and apply trigger to it. so you have 2 scripts 1 is EnemyController attach one by one to enemy to controll it and 1 is spawnController to spawn it.
Answer by Cynikal · Sep 09, 2016 at 07:33 PM
How are you calling the enemy chase function? If it's a static, that's why.
Your answer
![](https://koobas.hobune.stream/wayback/20220612092442im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
What does desiredVelocity do? 0 Answers
Set Destination can only be called on an active agent, problem when instanciating. 0 Answers
Update the navmesh after carving 1 Answer
Is it possible to rebake Navmesh surface during runtime? 0 Answers
Navmesh Agent - The Y Next Position & Y Velocity does not update if there is no X velocity. 0 Answers