Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Hack N Slash movement animation – how to end animation?

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);  
             
                
  
             }
 

    }
   
}

}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Try this:

if(agent.remainingDistance < 0.1)
{
  animator.SetBool("...", false);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading