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