Attack Animation

I’m making an RPG but the problem is my Attack animation loops forever altough i chose Once from inspector. I also made WrapMode.Once and nothin has changed. I plan on making a wait command till animate is finished than stop the animation and repeat it. Do you have any clues?

Here is my Code:
using UnityEngine;
using System.Collections;

public class Wander : MonoBehaviour 
{
    public Transform target;

    public float attackRange;
    public float moveSpeed;

    private CharacterController _controller;
    private Vector3 _moveDirection;

    private float _distance;
    private float _nextAttackAllowed=0;

	void Awake () 
    {
        target = GameObject.FindWithTag("Player").transform;
	}

    void Start()
    {
        _controller = GetComponent<CharacterController>();
        animation.wrapMode = WrapMode.Once;
    }

	void Update ()
    {
        _distance = Vector3.Distance(transform.position, target.position);

        transform.LookAt(target);
        _moveDirection = transform.TransformDirection(Vector3.forward);
        _controller.Move(moveSpeed * _moveDirection * Time.deltaTime);
        animation.CrossFade("ghost_idle_hover");
        
        if (_distance <= attackRange)
        {
            animation.CrossFade("ghost_attack_with_ball");
        }
	}
}

Double check your if condition (_distance <= attackRange).

Confirm that your condition is not getting executed all the time (because its in an Update method and Update is executed for each frame) and hence making it look like the animation is looping because it is getting executed once for each frame all the time.

You can do the following to debug the condition values:

Debug.Log("the distance value =" + _distance + " and attackRange=" + attackRange);

Fixed it with this code:

        if (_distance <= attackRange)
        {
            if (_timer <= 0)
            {
                animation.Play("ghost_attack_with_ball");
                _timer = cooldown;
            }
            else
            {
                _timer -= Time.deltaTime;   
            }
        }

Now the only problem is that it doesn’t wait till the animation is done.