- Home /
 
               Question by 
               Subzero619 · Oct 15, 2012 at 08:44 PM · 
                animationai  
              
 
              How to make an animation play for AI?
I made a script which makes the AI attack me and decrease my health unfortunately I have no idea on how to get the animation to play with it.
The attack script: using UnityEngine; using System.Collections;
 public class EnemyAttack : MonoBehaviour {
     public GameObject target;
     public float attackTimer;
     public float coolDown;
     
     // Use this for initialization
     void Start () {
         attackTimer = 0;
         coolDown = 1.0f;
     }
     
     // Update is called once per frame
     void Update () {
         if(attackTimer > 0)
             attackTimer -= Time.deltaTime;
             
         if(attackTimer <0)
             attackTimer = 0;
         
             if(attackTimer == 0) {
                 Attack();
                 attackTimer = coolDown;
         }
     }
     private void Attack() {
         float distance = Vector3.Distance(target.transform.position, transform.position);
         
         Vector3 dir = (target.transform.position - transform.position).normalized;
         
         float direction = Vector3.Dot(dir, transform.forward);
         
         Debug.Log(direction);
         
         if(distance < 2.5f) {
             if(direction > 0) {
             PlayerHealth ph = (PlayerHealth)target.GetComponent("PlayerHealth");
             ph.AddjustCurrentHealth(-10);
             }
         }
     }
 }
How do I make an animation work with this?
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Unity3D AI using animations 1 Answer
Couple of questions regarding AI scripts and animation? 1 Answer
Animay play in editor 0 Answers
Enemy Animation Freezing in first frame 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                