- Home /
How do I make the enemy ai animations play after the player exit the on trigger collider on the enemy ai
I am having a problem . The problem is the animations is play to soon. I have an on trigger collider on my enemy ai . The problem I am having is that the animations are playing right when I play the scene . How do I make the animation play on enemy ai play after the player exit the collider. Here is what I got for code :
using UnityEngine;
using System.Collections;
public class Enemy11 : MonoBehaviour {
public Transform player;
static Animator anim;
void Start () {
anim = GetComponent<Animator> ();
}
void OnTriggerExit (Collider other)
{
float speed = 0.2f;
this.transform.Translate(0,0,speed * Time.deltaTime);
if (Vector3.Distance(player.position, this.transform.position) < 10)
{
Vector3 direction = player.position - this.transform.position;
direction.y = 0;
this.transform.rotation = Quaternion.Slerp (this.transform.rotation,Quaternion.LookRotation(direction), 0.1f);
anim.SetBool("isIdle",false);
if(direction.magnitude > 2.6 )
{
this.transform.Translate(0,0,0.09f);
anim.SetBool("isMoving",true);
anim.SetBool("isAttack",false);
}
else
{
anim.SetBool("isAttack",true);
anim.SetBool("isMoving",false);
}
}
else
{
anim.SetBool("isIdle",true);
anim.SetBool("isMoving",false);
anim.SetBool("isAttack",false);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
C#: Climb ledge while inside collider 1 Answer
Collider Activate Trigger Animation 0 Answers
Trigger animation going crazy 3 Answers
Is this script rightfor trigering animation? 1 Answer
Triggering door animation with collider 2 Answers