public class EnemyAI : MonoBehaviour
{
public Transform Player;
private Animator anim;
private Rigidbody rb;
public float MoveSpeed = 1f;
public float MaxDist = 10f;
public float MinDist = 1f;
void Start()
{
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody>();
}
void Update()
{
EnemyMovement();
EnemyAttack();
}
void EnemyMovement()
{
if (Vector3.Distance(transform.position, Player.position) <= MinDist)
{
Walk(false);
}
else
if (Vector3.Distance(transform.position, Player.position) <= MaxDist)
{
transform.LookAt(Player);
transform.position = transform.position + transform.forward * MoveSpeed * Time.deltaTime;
Walk(true);
}
else
{
Walk(false);
}
}
void EnemyAttack()
{
if (Vector3.Distance(transform.position , Player.position) <= MinDist)
{
anim.SetTrigger("Attack1");
}
if (Vector3.Distance(transform.position, Player.position) <= MinDist)
{
anim.SetTrigger("Attack2");
}
if (Vector3.Distance(transform.position, Player.position) <= MinDist)
{
anim.SetTrigger("Attack3");
}
}
void Walk(bool move)
{
anim.SetBool("Movement", move);
}
Why don’t you remove the other 2 if statements and put everything in the first? So when the enemy is within distance you can perform all 3. Notify if there is something else going on after the first attack has been triggered.
@gamo_logics
Its because at “EnemyAttack()” funtion the first condition got true so Enemy plays “Attack1” but at the same time trigger for “Attack2” and “Attack3” been called but i guess there is no transition form “Attack1”
to “Attack2”. so If want to play all of these animation in sequence then you have to make transition from “Attack1” to “Attack2” and from “Attack2” to “Attack3”. some thing like:

also put all of the animator calls withing same one “If” like this:
if (Vector3.Distance(transform.position , Player.position) <= MinDist)
{
anim.SetTrigger("Attack1");
anim.SetTrigger("Attack2");
anim.SetTrigger("Attack3");
}
@imrankhanswati
Here is the transition I try different ways but failed to achieve what I want…