Animation Problem

Hi guys im creating a click to move script that walk with left mouse button and attack with right one. the move is working fine but when i press attack key (right mouse button) nothing happen. Wt am i missing here?

Another thing im getting this warning too:
Assets/Scripts/Rpg/ClickToMove.cs(9,19): warning CS0108: ClickToMove.animation' hides inherited member UnityEngine.Component.animation’. Use the new keyword if hiding was intended

This is the script
Appreciate any help

using UnityEngine;
using System.Collections;

public class ClickToMove : MonoBehaviour
{
  
    NavMeshAgent navAgent;

    Animation animation;

    public AnimationClip runAnimation;
    public AnimationClip idleAnimation;

    public static bool isAttacking;

    bool isAttacking = false;

  
    void Awake()
    {
        animation = GetComponent<Animation> ();
        isAttacking = false;
    }

    public AnimationClip attackAnimation;
  
    // Use this for initialization
    void Start ()
    {
        navAgent = GetComponent<NavMeshAgent>();
    }

    // Update is called once per frame
    void Update ()
    {
        Move ();
        Animate ();
    }
  
    void Move()
    {
        RaycastHit hit;
        Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
      
        if (Input.GetMouseButtonDown (0))
        {
            if(Physics.Raycast(ray, out hit, 100))
            {
                navAgent.SetDestination(hit.point);
              
            }
        }
    }
  
    void Animate()
    {
        if (navAgent.velocity.magnitude > 0.5f) {
            animation.CrossFade (runAnimation.name);
        }
        else
        {
            animation.CrossFade (idleAnimation.name);
        }
    }

    void Attack()
    {
        if (Input.GetMouseButtonUp(1))
        {
            isAttacking = true;
            animation.CrossFade (attackAnimation.name);
        }
    }
}

First of all, rename your variable animation. There is alreay a variable named animation in the base class and that is why Unity is complaining.

Secondly, you don’t actuall call the Attack method anywhere. So the code doesn’t run. Add it to your Update() and things should work properly.

The issue disapear but about the attack even calling the Attack() method in update in game nothing happen and i get no errors too.

Isn’t the problem because you are running Animate() each frame, which starts an animation even if isAttacking is true? That way you will never see your attack animation, since it is overridden all the time.

im guessing you mean it only ever plays walking animation… you’re going to have to look into bones/layers/weights if you want to play attack/walk/run at the same time, or ensure its playing one or the other.

For now i just want it to walk and if is attacking is not walking… But even i call Animate inside Move method the attack dont work… Latter i will try implement a ability system but i hv time for that just want things simple or now

Try to comment out Animate(), then you should see your attack animation.

Yes the question is i want 2 working… but i figure other way out. Ty

Just do something like this:

    void Animate()
    {
        if(!isAttacking)
        {
            if (navAgent.velocity.magnitude > 0.5f) {
                animation.CrossFade (runAnimation.name);
            }
            else
            {
                animation.CrossFade (idleAnimation.name);
            }
        }
    }
    // The time the anim takes to complete
    float attackDelay = 1.0f;
    float attackOverTime = 0;
   
    void Attack()
    {
        if (Input.GetMouseButtonUp(1))
        {
            isAttacking = true;
            animation.CrossFade (attackAnimation.name);

            attackOverTime = Time.time + attackOverTime;
        }

        if( Time.time > attackOverTime )
        {
            isAttacking = false;
        }
    }

ty m8 i will get a try… appreciaye.