NavMeshAgent agent = GetComponent(); agent.SetDestination(targetPosition);
NavMeshAgent agent = GetComponentIn this example, the destination point is set to the location where the user clicked on the screen. Overall, the SetDestination() method is a powerful tool for controlling the movement of AI characters in Unity, and it can be used in a variety of different scenarios.(); if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { agent.SetDestination(hit.point); } }