Im quite new to animation in Unity, does anybody know how in this loop I can set my bool to false when my Character will arrive at destination point? Most help I found on Internet was about controling your charracter with keyboard, but mine is conntroled by mouse clicks only.
{
Camera cam;
Animator animator;
NavMeshAgent agent;
private void Start()
{
animator = GetComponent<Animator>();
cam = GameObject.Find("Main Camera").gameObject.GetComponent<Camera>();
agent = this.gameObject.GetComponent<NavMeshAgent>();
}
private void Update()
{
if (Input.GetMouseButtonDown(0)) {
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
animator.SetBool("Isrunning", true);
if (Physics.Raycast(ray, out hit)) {
agent.SetDestination(hit.point);
}
}
}
}
CodePudding user response:
Try this:
if(agent.remainingDistance < 0.1)
{
animator.SetBool("...", false);
}