How to change speed for a cloned prefab instead of applying it to all instances of prefab?
Hello,
I have a NavMeshAgent that loops around a path. The Prefab has a tag set to "car". I can make an instance of the prefab by pressing a button. The prefab has a box collider which acts as trigger sensor (this was a quick implementation to determine if anything is in front of the prefab).
In my code I have the trigger box detecting if there's a car colliding with it that it shoudl stop before the mesh of the prefab collides with whatever is in front of it, and then resume after the car in front is not in the trigger zone.
private void OnTriggerEnter(Collider other){
switch (other.tag){
case "car": // if there's a car obj in front, stop
agent.Stop();
break;
}
}
private void OnTriggerExit(Collider other){
switch (other.tag) {
case "car":
agent.Resume ();
break;
}
}
My issue is that if I spawn 2 of my NavMeshAgent with a bit of a delay in between, if the last spawned agent detects the other object in its trigger box zone, it will stop (as intended) but the agent that in front of it will also stop. How do I make it so that only the object behind the navmeshagent is only affected and not all instances of the prefab?
Thanks
Answer by TareqProjects · Dec 12, 2016 at 03:42 PM
Quick comment; In the title I wrote that I want to change the speed, this is a typo on my end. I meant to say how do I prevent all instances of a NavMeshAgent from stopping.
Apologies
Your answer
Follow this Question
Related Questions
Change NavMeshAgent Speed With Script? 1 Answer
Object reference not set to an instance of an Object? 0 Answers
how can I implement navmesh in this script? 0 Answers
Help with good coding practices and player Nav Mesh Agent Jumps. Thanks. 1 Answer
Creating prefab through Zenject Factory makes navMeshAgent act strange 0 Answers