Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Reagle606 · Jun 02, 2014 at 05:14 AM · animationjavasystemmelee

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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Making an animation play when you press down 2 keys 1 Answer

Can someone please tell me whats wrong with my code - the error syas it expects to see ')' instead it saw 'hit' (the one after 'out') 1 Answer

Animation script error 1 Answer

animation help with falling when not grounded? 0 Answers

How do i make my attack function not work whilst animation playing? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges