- Home /
 
               Question by 
               importguru88 · May 21, 2016 at 05:47 PM · 
                c#animationslegacywrapmodewrap  
              
 
              How do I code legacy animations in wrap mode Unity C#
I having an issue with my animations . I need idle , move , attack , and death animation to work all together . I think having my animation in wrap mode would be my best bet . But I don't know how to approach this situation. What I am trying to do is have my enemy attack when the player is near , move with the player is not near , idle when the player is really far away ' idle when the player is dead, . I have all animations set on loop.
Here is what I got :
using UnityEngine; using System.Collections;
public class tty : MonoBehaviour { //nav mesh agent needed public Transform player; public float playerDistance; public float rotationdamping; public float moveSpeed ;
 void Start () {
 
 }
 
 
 void Update () {
 
 playerDistance = Vector3.Distance (player.position, transform.position);
 
 if (playerDistance < 4f)
 {
     lookAtPlayer();
 }
 
 if(playerDistance < 3f)
 {
     if(playerDistance > 2f)
     {
         chase();
     }
 
     else if(playerDistance < 2f)
     {
         attack();
     }
 
 }
 
 }
 
 void lookAtPlayer()
 {
     Quaternion rotation = Quaternion.LookRotation (player.position - transform.position);
     transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * rotationdamping);
     GetComponent<Animation>().Play("idle");
 }
 void chase()
 {
     transform.Translate(moveSpeed * Vector3.forward * Time.deltaTime);
     GetComponent<Animation>().Play("move");
 }
 void attack()
 {
     
     GetComponent<Animation>().Play("attack");
 }
}
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                