- Home /
 
              This post has been wikified, any user with enough reputation can edit it. 
            
 
            Why wont my animations play?
I cannot get the attack animations to play at all when i click. i'm very new to unity and i have no idea if i'm even going about it the right way. It all worked when i had it all in One script... but i wanted to have a separate one to control weapons so they can individually have animations.
Melee system code:
pragma strict
 var Damage : int = 5;
 var Distance : float;
 var MaxDistance : float = 10;
 var TheSystem : Transform;
 var Sword : GameObject;
 var CanAttack : boolean = true;
 
 
 
 if (Input.GetButtonDown("Attack") && CanAttack == true)
     {
 
         var hit : RaycastHit;
         if(Physics.Raycast (TheSystem.transform.position, TheSystem.transform.TransformDirection(Vector3.forward), hit))
         {
             Distance = hit.distance;
             if (Distance < MaxDistance)
             {
                 Sword.animation.CrossFade("AttackHit");
             }
         }
         else
             {
                 Sword.animation.CrossFade("Attack");
             }
 }
 function AttackDamage()
 {
         var hit : RaycastHit;
         if(Physics.Raycast (TheSystem.transform.position, TheSystem.transform.TransformDirection(Vector3.forward), hit))
         {
             Distance = hit.distance;
             if (Distance < MaxDistance)
             {
                 hit.transform.SendMessage("ApplyDamage", Damage, SendMessageOptions.DontRequireReceiver);
             }
         }
 }
 
               Player Movement Code:
 #pragma strict
 
 
 var PlayerAnimControl : GameObject;
 var PlayerCamera : GameObject;
 var PlayerState : float;
 var WalkingSpeed : float = 5;
 var SprintingSpeed : float = 9;
 var PlayerMainController : CharacterController;
 var CharacterMag : float;
 var CanSprint : boolean = true;
 var Sprinting : boolean = false;
 var Walking : boolean = false;
 var Standing : boolean = true;
 var PlayerMotor : CharacterMotor;
 var CanJump : boolean = true;
 var CanBlock : boolean = true;
 var Blocking : boolean = false;
 var Attacking : boolean = false;
 var CanAttack : boolean = true;
 var Hit : boolean = false;
 var Hurt : boolean = false;
 var Blocked : boolean = false;
 var Sword : GameObject;
 
  
 
 
 
 
 
 
 // state  0 = standing   1 = walking   2 = sprinting   3 = Blocking  4 = Attacking   5 = Hurt   6 = Blocked  7 = Hit
 
 function Update () 
 {
 CharacterMag = PlayerMainController.velocity.magnitude;
 
 
 
 if ((Input.GetAxis("Vertical") ==0 || Input.GetAxis("Horizontal") ==0))
     {     
      PlayerState = 0;
     }
     
     if (PlayerState == 0 && Attacking == false)
     {
         Sword.animation.CrossFade("Idle");
         Walking = false;
         Sprinting = false;
         Standing = true;
         CanSprint = true;
         CanBlock = true;
         Blocking = false;
         CanAttack = true;
         Attacking = false;
     }
     if ((Input.GetAxis("Vertical") !=0 || Input.GetAxis("Horizontal") !=0))
     {
         PlayerState = 1;
     }
     if (PlayerState == 1 && Attacking == false)
     {
         Sword.animation.CrossFade("Walk");
         Walking = true;
         Sprinting = false;
         Standing = false;
         CanSprint = true;
         CanBlock = true;
         Blocking = false;
         CanAttack = true;
         Attacking = false;
         
         PlayerMotor.movement.maxForwardSpeed = WalkingSpeed;
          PlayerMotor.movement.maxBackwardsSpeed = WalkingSpeed/2;
          PlayerMotor.movement.maxSidewaysSpeed = WalkingSpeed;
     }
     
 if ((Input.GetButton("Shift") && CanSprint == true && (Input.GetAxis("Vertical") !=0 || Input.GetAxis("Horizontal") !=0)))
     {
         PlayerState = 2;
     }
     
     if (PlayerState == 2)
     {
         Sword.animation.CrossFade("Sprint");
         Sprinting = true;
         Walking = false;
         Standing = false;
         CanSprint = true;
         CanBlock = false;
         Blocking = false;
         CanAttack = false;
         Attacking = false;
         PlayerMotor.movement.maxForwardSpeed = SprintingSpeed;
          PlayerMotor.movement.maxBackwardsSpeed = SprintingSpeed/2;
          PlayerMotor.movement.maxSidewaysSpeed = SprintingSpeed;
     }
     if (Input.GetButton("Fire2") && CanBlock == true)
     {
         PlayerState = 3;
     }
     if (PlayerState == 3)
     {
         Sword.animation.CrossFade("Block");
         CanBlock = true;
         CanSprint = false;
         CanJump = false;
         Sprinting = false;
         Blocking = true;
         CanAttack = false;
         Attacking = false;
         PlayerMotor.movement.maxForwardSpeed = WalkingSpeed/2;
          PlayerMotor.movement.maxBackwardsSpeed = WalkingSpeed/2;
          PlayerMotor.movement.maxSidewaysSpeed = WalkingSpeed/2;
         
     }
 
     
         
 
     
     if (Input.GetButton("F") && Blocking == false)
     {
         PlayerState = 5;
     }
     if (PlayerState == 5)
     {
         Sword.animation.CrossFade("Hurt");
         CanBlock = true;
         CanSprint = false;
         CanJump = false;
         Sprinting = false;
         Blocking = false;
         CanAttack = false;
         Attacking = false;
         Hurt = true;
         PlayerMotor.movement.maxForwardSpeed = 0;
          PlayerMotor.movement.maxBackwardsSpeed = 0;
          PlayerMotor.movement.maxSidewaysSpeed = 0;
         
     }
     
     if (Input.GetButton("F") && Blocking == true)
     {
         PlayerState = 6;
     }
     if (PlayerState == 6)
     {
         Sword.animation.CrossFade("Blocked");
         CanBlock = true;
         CanSprint = false;
         CanJump = false;
         Sprinting = false;
         Blocking = false;
         CanAttack = false;
         Attacking = false;
         Hurt = false;
         Blocked = true;
         PlayerMotor.movement.maxForwardSpeed = 2;
          PlayerMotor.movement.maxBackwardsSpeed = 2;
          PlayerMotor.movement.maxSidewaysSpeed = 2;
         
     }
     
 
 
 
 
 }
 
              
               Comment
              
 
               
              Answer by Andres-Fernandez · Jun 02, 2014 at 08:39 AM
If you imported the animation clips with the object, check if they are set as legacy in the editor (I think it is type 1 in the debug mode).
Your answer