- Home /
Detector NPC on trigger zone.
Hi! I have a very specific problem. I have a trigger zone, inside of which there is a "Point". I want to make sure that some NPCs that have entered the zone can go to the "Point". NPCs will stand on the "Point" for 10 seconds, after which they will leave. In this case, at the same time there can be only one npc at this "Point". The problem is, I do not know how to let the NPC know that the "Point" is "busy" or "free".
Exit the trigger zone - not suitable, because out of the zone there may be NPCs not standing near the point.
Thanks!
Add a bool variable to the point script like 'busy'. When npc enters check if (busy == false), if yes then set it to true and set the destination point for the npc (you can get the npc transform from the Collider param of the OnTriggerEnter method). When npc left the zone set the variable to false for next npc.
A good idea, but how can I find out what NPC is out of the zone? I mean, the zone can leave the NPC which did't stand near the point.
then use a bool and and an int to representing which NPC is there. every NPC should have and know it's number.
If using Nav$$anonymous$$esh then you may setup this "Point" as small separate Nav$$anonymous$$esh area and manipulate entrance by changing UnityEngine.AI.Nav$$anonymous$$esh.SetAreaCost() or adding/removing Nav$$anonymous$$esh links to it (UnityEngine.AI.Nav$$anonymous$$esh.AddLink()) for example. AI's may check if they can access this place via navmesh calculation in their update loops. This way you won't have to implement other notification methods.
Your answer
![](https://koobas.hobune.stream/wayback/20220612131051im_/https://answers.unity.com/themes/thub/images/avi.jpg)