hi again, after i get my player to work properly with mecanim i try it with my enemy, the enemy stay in idle, run when in range of chase player but when it get in attack range, it gives the damage has it should but instead of playing attack animation it keep running at same spot… i check the animator window and i can see this…
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Enemy : HumanoidControl
{
Player player;
public float chasingRange;
bool blockEnemy;
bool mouseOver;
NavMeshAgent navAgent;
private Animator anim;
private bool running;
private bool attacking;
void Start ()
{
player = Player.player;
navAgent = GetComponent<NavMeshAgent>();
mouseOver = false;
anim = GetComponent<Animator>();
}
void Update ()
{
Attack();
FollowPlayer();
}
void FollowPlayer()
{
if (IsInRange (chasingRange))
{
running = true;
attacking = false;
navAgent.SetDestination (player.transform.position);
navAgent.Resume();
}
else
{
//change this to return initial position
navAgent.SetDestination(transform.position);
}
anim.SetBool ("IsRunning", running);
}
void OnMouseOver()
{
Player.opponent = transform;
}
protected override void Attack()
{
if (IsInRange(attackRange))
{
if(!blockEnemy)
{
player.GetHit(damage);
attacking = true;
anim.SetTrigger("IsAttacking");
blockEnemy = true;
Invoke("UnBlock", attackSpeed);
}
anim.SetBool ("IsAttacking", attacking);
}
if(Vector3.Distance(player.transform.position, transform.position) < attackRange)
{
attacking = true;
}
else
{
attacking = false;
}
anim.SetBool ("IsAttacking", attacking);
}
void UnBlock()
{
blockEnemy = false;
}
bool IsInRange(float range)
{
if(Vector3.Distance (player.transform.position, transform.position) < range)
{
return true;
}
else
{
return false;
}
}
}