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 masterp · Jan 17, 2013 at 04:10 PM · animationcharactercharacter animation

Adding another animation to this script

I currently have idle, walk and sword attack animations running fine for my character using the script from unity docs. The problem I am having is when I try add another animation. The newer animation added will stop all the rest from working, for instance if I add "WalkLeft" that will be the only one to play.

The input settings are done so would this small piece of code just need to be added to the script or have a made a mistake:

 if (Mathf.Abs(Input.GetAxis("Horizontal")) > 0.1)
       animation.CrossFade("WalkLeft");



The code I have used is the following one:

 function Start () {
    // Set all animations to loop
    animation.wrapMode = WrapMode.Loop;
    // except shooting
    animation["SwordAttack1"].wrapMode = WrapMode.Once;
 
    // Put idle and walk into lower layers (The default layer is always 0)
    // This will do two things
    // - 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 higher layer, the animation will replace idle/walk
    //   animations when faded in.
    animation["SwordAttack1"].layer = 1;
 
    // Stop animations that are already playing
    //(In case user forgot to disable play automatically)
    animation.Stop();
 }
 
 function Update () {
    // Based on the key that is pressed,
    // play the walk animation or the idle animation
    if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1)
       animation.CrossFade("Walk");
     else
       animation.CrossFade("Idle");
       
 
    // Shoot
    if (Input.GetButtonDown ("Fire1"))
       animation.CrossFade("SwordAttack1");
 }

Any help would be appreciated.

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 dorpeleg · Jan 17, 2013 at 05:18 PM 0
Share

Can you explain more? you add the code and then what happens? do the WalkLeft play and nothing else plays after it? is it something else?

2 Replies

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

Answer by dorpeleg · Jan 17, 2013 at 06:16 PM

Try writing it like this:

 if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1){
       animation.CrossFade("Walk");
     }else if (Mathf.Abs(Input.GetAxis("Horizontal")) > 0.1){
       animation.CrossFade("WalkLeft");
     }else
       animation.CrossFade("Idle");

See if it works for you.

Comment
Add comment · Show 2 · 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
avatar image masterp · Jan 17, 2013 at 06:22 PM 0
Share

That works perfectly!!!!!!!!!!!!

I played around for a while (newbie), in the end it was as simple as that.

Thanks for your help

avatar image dorpeleg · Jan 17, 2013 at 06:23 PM 0
Share

Please mark this answer as Accepted :)

avatar image
0

Answer by masterp · Jan 17, 2013 at 05:24 PM

Basically you got it,if I add my walkleft code no other animations will play other than that one

Comment
Add comment · Show 2 · 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
avatar image dorpeleg · Jan 17, 2013 at 05:33 PM 0
Share

Please put your replay as a comment next time. Do the other animations not work from the start? or only after you run the WalkLeft once?

avatar image masterp · Jan 17, 2013 at 05:37 PM 0
Share

If i use the larger piece of code i posted above, my walk, idle and sword attack work. $$anonymous$$y problem is that if another animation is added to this code only the newer animation will play, all others stop.

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

10 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

Related Questions

How can I use a joystick for a mobile app to control specific limbs of a character? 0 Answers

Importing Animations to Unity from maya! 1 Answer

How to use Blender actions in Unity timeline? 0 Answers

My character is not moving when playing animation 0 Answers

Making Character Stand? 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