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 /
avatar image
0
Question by adrennalinpro · Apr 22, 2014 at 06:15 AM · animationsstop

Animations won't play on command

So I have a script that calls certain animations when events occur. Like if the button for sprinting is pressed, then play the sprint animation. But only a few work, like the walk animation, the idle animation, and the shoot animation. Any ideas as to why these won't play when told to?

 var WalkAnim : String = "Walk";
 var IdleAnim : String = "Idle";
 var FireAnim : String = "Firing";
 var AimAnim : String = "AimIdle";
 var RunAnim : String = "Run";
 var ReloadAnim : String = "Reload";
 var PlayWhileAiming = false;
 var WalkSpeedModifier : float = 8;
 var WalkSpeedMultiplier : float = 2;
 var Fire : GameObject;
 var Reloading : boolean;
 private var DefaultPos : Vector3;
 private var Controller : CharacterController;
 
 function Start () {
 
     DefaultPos = transform.localPosition;
     Controller = GameObject.FindGameObjectWithTag("Player").GetComponent(CharacterController);
 
 }
 
 function Update () {
 
     if(Input.GetAxis("Vertical")||Input.GetAxis("Horizontal")){
     gameObject.animation.CrossFade(WalkAnim,0.4);
     gameObject.animation[WalkAnim].speed = Controller.velocity.magnitude / WalkSpeedModifier * WalkSpeedMultiplier;
     }
     
     else 
     {
         transform.localPosition = Vector3.Lerp(transform.localPosition,DefaultPos,0.4);
         gameObject.animation.CrossFade(IdleAnim);
     }
     
     if(Input.GetButton("Fire1") && PlayWhileAiming == false && Fire.GetComponent(FireScript2).CanFire == true){
 
     transform.localPosition = Vector3.Lerp(transform.localPosition,DefaultPos,5);
     gameObject.animation.Play(FireAnim);
     
     if(Input.GetButton("Fire2") || Input.GetKey("e") && PlayWhileAiming == false){
 
     transform.localPosition = Vector3.Lerp(transform.localPosition,DefaultPos,5);
     gameObject.animation.Stop(WalkAnim);
     
     if(Input.GetKey("q") || Input.GetKey("left shift") && PlayWhileAiming == false){
 
     transform.localPosition = Vector3.Lerp(transform.localPosition,DefaultPos,5);
     gameObject.animation.CrossFade(RunAnim);
     
     
     Reloading = false;
     
     if(Input.GetButton("Reload")) {
     Reloading = true;
     }
     
     if(Reloading == true){
 
     transform.localPosition = Vector3.Lerp(transform.localPosition,DefaultPos,5);
     gameObject.animation.CrossFade(ReloadAnim);
     
                 }
             }
     
         }
 
     }
 
 }
Comment
Add comment · Show 4
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
avatar image NickP_2 · Apr 22, 2014 at 06:22 AM 0
Share

Have you checked all import settings for the animation rig? $$anonymous$$ake sure thr ones who dont work have the same as the ones who do.

Ive also had an animation problem, looked for days, and finally found out the imported scale was different... There are so many things thay could go wrong, Im just trying to elli$$anonymous$$ate a few already :)

avatar image adrennalinpro · Apr 22, 2014 at 06:33 AM 0
Share

Well I tried calling the animations from an external script, aside from this one, and it works. Apparently, I have too many animations being called in this script, or something..

avatar image maddFrogg · Apr 22, 2014 at 07:25 AM 0
Share

I see you use animation which is kind of obsolete since $$anonymous$$ecanim came out. I recommend you to use it since it is more clear.

Even though, if you want to keep using legacy animations you still can, but you need to mark every take (.anim file) as legacy. How? Select the animation and right click on the inspector label. Select Debug and change Animation Type to 1 (it should be 2 before you change it).

Try this and tell us if it is fixed.

avatar image adrennalinpro · May 20, 2014 at 04:07 AM 0
Share

Ugh.. I wish I had seen this sooner! I went ahead and put the calling for some of the animations into different scripts, and that fixed it all up. I'm not sure if it was the $$anonymous$$ecanim problem or not, but if the issue occurs again I shall definitely try your suggestion. Thanks!

0 Replies

· Add your reply
  • Sort: 

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

Make ALL animations stop! 1 Answer

Any way to stop a build? 3 Answers

Track time between 1 Answer

Audio won´t stop 0 Answers

What will StopCoroutine exactly do? 2 Answers


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