Animator issue

Hi guys im trying to implement animator in my click to move game but right now im haveing an issue, the idle works fine but when i try run the character keep idle and only sometimes turn to running.

I hv my animator like the image bellow with 2 parameters, so i change idle to run when IsRunning is true and vice-versa:

  • bool IsRunning
  • trigger Die

And i hv this script attached to player, can anyone help plz???

using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine.UI;

    
public class ClickToMove : MonoBehaviour
{
    

    NavMeshAgent navAgent;


    public float attackDistance = 10f;

    public float attackRate = 0.5f;

    private Animator anim;

    private Transform targetedEnemy;

    private Ray shootRay;

    private RaycastHit shootHit;

    private bool running;

    private bool enemyClicked;

    private float nextHit;

    // Use this for initialization
    void Awake ()
    {
        anim = GetComponent<Animator>();

        navAgent = GetComponent<NavMeshAgent>();
    }

   
    void Update()
    {
        Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
        RaycastHit hit;
        if (Input.GetMouseButtonDown(0))
        {
            if(Physics.Raycast(ray, out hit, 100))
            {
                if(hit.collider.CompareTag("Enemy"))
                {
                    targetedEnemy = hit.transform;
                    enemyClicked = true;
                }
                else
                {
                    running = true;
                    enemyClicked = false;
                    navAgent.destination = hit.point;
                    navAgent.Resume();
                }
            }
        }

        if (enemyClicked)
        {
            MoveAndHit();
        }

        if (navAgent.remainingDistance <= navAgent.stoppingDistance)
        {
            running = false;
        }
        else
        {
            running = true;
        }

        anim.SetBool ("IsRunning", running);
    }

    private void MoveAndHit()
    {
        if (targetedEnemy == null)
            return;
         navAgent.destination = targetedEnemy.position;
        if (navAgent.remainingDistance >= attackDistance)
        {
            navAgent.Resume();
            running = true;
        }

        if (navAgent.remainingDistance <= attackDistance)
        {
            transform.LookAt(targetedEnemy);
            Vector3 dirToHit = targetedEnemy.transform.position - transform.position;

            if(Time.time > nextHit)
            {
                nextHit = Time.time + attackRate;
                //attackmethod
            }
            //navAgent.Stop();
            //running = false;
        }
    }
}

Remove the exit time from the transition.

It works but now i hv a problem after idle animation run 1st time, then its not looping if i stay stopped… All the rest works fine now.

Not looping? The animation? Make sure you make the animation clip looped. Select the clip in your project and set it to loop.

I check now that i get a warning at line 78 saying Animator has not been initialized…

can you also post your attack method ?

It works ty m8

i dont hv attack method yet loool… im trying figure it out xD im kind new in this things

instead of using bools to check the current action, use state machine. its basically an enum and a switch case in update method.

I just follow some tutorial for this one cuz im not very familiar with state machines and animations… :frowning: and if will have lots of problems when i implement combat for sure lol