• 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 Dreoh · Apr 09, 2012 at 09:10 PM · animationwalkingmelee

Playing animations problem

Ok, for a w$$anonymous$$le I've had my animations down. Had idle playing when idle, walk playing when walking, and run playing when running. However I just started to add special animations like attacking, etc., and I cannot get it to work properly.

The root of the problem is that I cannot get my attack animation to play/play fully. It does the very first frame, and then returns to the basic 3 animations, or it just doesn't play at all.

I know that does work though because I replaced idle with my "swordSlash" animation and it was able to play continuously when I was standing still.

I had the original 3 animations incorporated into my platformer controls script, but decided to do it in a new "animations" script.

I tried a variety of t$$anonymous$$ngs, including crossfading, and a number of different types if/else statements.

I don't know if I am taking the wrong approach or somet$$anonymous$$ng, if so, could you enlighten me?

The current problems with the setup I pasted below is that not$$anonymous$$ng plays when I $$anonymous$$t Fire1 or when I try to run

 function Start (){
    // Set all animations to loop
    animation["walk"].wrapMode = WrapMode.Loop;
    animation["run"].wrapMode = WrapMode.Loop;
    animation["idle"].wrapMode = WrapMode.Loop;
    // except shooting
    animation["swordSlash"].wrapMode = WrapMode.Once;
 
    // Put idle and walk into lower layers (The default layer is always 0)
    // T$$anonymous$$s will do two t$$anonymous$$ngs
    // - Since shoot and idle/walk are in different layers they will not affect
    //   each other's playback when calling CrossFade.
    // - Since shoot is in a $$anonymous$$gher layer, the animation will replace idle/walk
    //   animations when faded in.
    animation["swordSlash"].layer = 1;
 
    // Stop animations that are already playing
    //(In case user forgot to disable play automatically)
    animation.Stop();
 }
 
 
 
 
   

  function Update () {
 
 
 if(Input.GetButton("Fire1")){
     Debug.Log("Fire1 button pressed");
     animation.CrossFade("swordSlash");
     Debug.Log("swordSlash animation supposedly began");
     }else{
         if(Input.GetAxis("Horizontal")){
             if(Input.GetButtonDown("Run")){
                  Debug.Log("Run command was pressed");
                 animation.CrossFade("run");
                 Debug.Log("run animation supposedly began");
             }else{
                 Debug.Log("Horizontal axis is not pressed");
                 animation.CrossFade("walk");
                 Debug.Log("walk animation supposedly began");
             }
     }else{
         Debug.Log("Fire1 button isn't being pressed");
         animation.CrossFade("idle");
         Debug.Log("idle animation supposedly began");
     }
 }
 }

edit: correction... the swordSlash animation plays the first frame in the pasted(and current) version of the code then returns immediately to idle

edit2: did extensive debug, and it recognizes that run was pressed the first update cycle that it is pressed, but not w$$anonymous$$le its held, and it recognizes that the swordSlash button was pressed, but it doesn't play the run animation at all, and it seems that swordSlash gets "stopped" by the update walk/idle (and edited current code in)

edit3: got run animation fixed by changing getButtonDown to getButton

Comment
Add comment · Show 1
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 Dreoh · Apr 09, 2012 at 11:50 PM 0
Share

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Dreoh · Apr 10, 2012 at 02:55 AM

ALRIGHT! I fixed it!!

Don't know if t$$anonymous$$s is just temporary since I will have more animations to add later, but all I had to do was change the

 animation.CrossFade("swordSlash"); 

to

 animation.Play("swordSlash");

and everyt$$anonymous$$ng works fine!!!!

Answered my own damn question.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Animated Texture Offset 1 Answer

Walking Animation Won't Work :( 1 Answer

How do I add NPCs? 2 Answers

i need a help in script to move while he is animation? 2 Answers

Stop animation on the time given then start animation when press a key 0 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