This is a simple class that does three things:
- Gets the mouse click position using a ray
- Updates the marker position
- Updates the destination property of all the NavMesh agents
The following lines show the code's that present in this class:
using UnityEngine; using System.Collections; public class Target : MonoBehaviour { private NavMeshAgent[] navAgents; public Transform targetMarker; void Start() { navAgents = FindObjectsOfType(typeof(NavMeshAgent)) as NavMeshAgent[]; } void UpdateTargets(Vector3 targetPosition) { foreach (NavMeshAgent agent in navAgents) { agent.destination = targetPosition; } } void Update() { int button = 0; //Get the point of the hit position when the mouse is //being clicked if(Input.GetMouseButtonDown(button)) ...