• 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 rakesh12 · Aug 11, 2012 at 10:56 AM · animationcrossfade

how to play different animation

I m trying to play 2 animation run & jump ,in inspector both have take001 animation,i m using crossfade but my program is not working,can any one help ? code

 public class Doubleanimation : MonoBehaviour
 {
     public Animation Man_jump, Man_walk;
     
     void Start ()
     {
         animation.wrapMode = WrapMode.Once;
         animation.AddClip(animation.clip, "Man_walk");
         animation.AddClip(animation.clip,"Man_jump");
     }
  
     void Update () 
     { 
         animation["Man_walk"].wrapMode = WrapMode.Once;
         animation["Man_jump"].wrapMode = WrapMode.Loop;
         animation["Man_walk"].layer = 0;
         animation["Man_jump"].layer=1;
         if (Input.GetAxis("Vertical")>0.2)
         {
             animation.CrossFade("Man_walk");
             //animation.Stop();
         }
         else
         {
             animation.CrossFade("Man_jump");
         }
     }
 }
Comment
Add comment · Show 5
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 Ingen · Aug 11, 2012 at 11:19 AM 0
Share

showing your code, easily can have a good answer,

past code editing your answer, after past the code select it all and press the 101010 button

avatar image TheDavil86 · Aug 11, 2012 at 02:21 PM 0
Share

Yea that's really hard to read, i can see you have a lot of things commented out though.

avatar image FLASHDENMARK · Aug 11, 2012 at 02:27 PM 0
Share

I formatted your code for you. Hopefully I didn't ruin anything.

avatar image rakesh12 · Aug 13, 2012 at 04:18 PM 0
Share

i think u have not try to understand the code , i solve out my problem my code is running well..

avatar image Bunny83 · Aug 13, 2012 at 04:20 PM 0
Share

@rakesh12: don't post replies as answers. This is a Q&A site. Answers should answer the question. For annotations there are comments (the "add new comment" button).

I've converted your answer into a comment

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Aug 13, 2012 at 04:38 PM

Those two lines doesn't make mush sense:

 animation.AddClip(animation.clip, "Man_walk");
 animation.AddClip(animation.clip,"Man_jump");

You add the default clip of the animation component 2 more times to the component with a different name. Also your two public Animation references seems to be a bit strange. What other animation components have you linked there? I guess you want to add AnimationClips. So either add the clips in the inspector directly to the Animation component, or if you want to add them via code, make the public variables of type AnimationClip and add them to the animation component.

Next thing is: wrapmode and layers should be set in Start and not in Update (unless you plan to overwrite them somewhere at some time).

Last thing is:I guess you mixed up your animations. the walk animation should be looping and the jump animation should be playing once. Also You play the animation again and again while the input axis is greater than 0.2. Are you sure that's what you want? Usually a jump is a one time action and you should use Input.GetButtonDown, but that's a conceptual thing we can't answer for you.

 public class Doubleanimation : MonoBehaviour
 {
     public AnimationClip Man_jump, Man_walk; // assign in the inspector
     
     void Start ()
     {
         animation.wrapMode = WrapMode.Once;
         animation.AddClip(Man_walk, "Man_walk");    
         animation.AddClip(Man_jump, "Man_jump");
         animation["Man_walk"].wrapMode = WrapMode.Loop;
         animation["Man_jump"].wrapMode = WrapMode.Once;
         animation["Man_jump"].layer = 1;
     }
  
     void Update () 
     { 
         if (Input.GetAxis("Vertical") > 0.2)
         {
             animation.CrossFade("Man_walk");
         }
         else
         {
             animation.CrossFade("Man_jump");
         }
     }
 }


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

11 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

Related Questions

Play an animation just on some parts of the body 1 Answer

Shaking skinned mesh animations 1 Answer

Animation: Impact of combining the use of Layer, CrossFade, and Weight 2 Answers

how to crossfade a animation and then loop it 1 Answer

Crossfade from ragdoll bones to animation 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