- Home /
How to move a single specific NavMesh agent?
I have several navMesh agents in a game. When a player chooses specific one (from a list) I need only that agent to move to a certain place, while other agents will remain unaffected by this choice.
Is this possible using Unity? What would be the best way to do this?
Thank you
Answer by jmhoubre · Oct 30, 2021 at 09:26 AM
Hello, the easiest way, as a beginner, is to add a Collider to your agents and add in the control script of these agents an OnMouseDown function, which is called by Unity (a bit like OnTrigerEnter). When you click on the agent, it executes the function (here, if it moves, it stops, and vice versa).
private void OnMouseDown ()
{
agent.isStopped = !agent.isStopped;
}
Little demo : https://drive.google.com/file/d/1Ri-zd0QMchAT3LPhDeqSxIHChssR6U5X/view?usp=sharing
Answer by jmhoubre · Oct 28, 2021 at 07:44 PM
Hello, you can SetDestination for this agent.
Hello jmjoubre,
Thank you for the reply.
How would I exactly target that one selected agent? (there are around 10 prefabs with NavMesh Agent component) Is there an agent list where I could target the chosen one with an index or?
Obviously, I'm very new to Unity so forgive for the possibly stupid question :)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Nav Agent Moving Only Forwards And Backwards 0 Answers
Multiple NavmeshAgents waiting each other to move to destination?? 1 Answer
All my NavMeshAgents are tilted 1 Answer