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 convictcartel · Feb 02, 2014 at 01:34 AM · animationplaycrossfade

Playing several animations

Im having problems, my walk and idle work fine but when i press my button to call an attack script it plays a second but cuts off the rest of the animation.

     if ( moveTouchPad.position.x > 0)
      transform.rotation = Quaternion.Euler(0,90,0);
     animation.CrossFade("walk");
     
     if ( moveTouchPad.position.x < 0)
     transform.rotation = Quaternion.Euler(0,-90,0);
     animation.CrossFade("walk");
     
     if ( moveTouchPad.position.x == 0 && attack == true)
     animation.CrossFade("idle");

 function OnGUI() {
         if (GUI.Button(Rect(10,Screen.height / 2,50,50),btnTexture))
         {
         animation.Play("attack");
         }
             }
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 supernat · Feb 02, 2014 at 07:38 AM 0
Share

I think you need to check attack == true for the walk animations. You're also calling CrossFade("walk") in the main loop, forget some brackets? I think you need to put the transform and CrossFade calls in brackets.

1 Reply

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

Answer by RyanZimmerman87 · Feb 02, 2014 at 02:24 AM

First of all you should probably remove the:

animation.Play("Attack") from OnGUI()

I don't think it's necessary to do so but that seems like an odd way to do things, I would probably set up an attack bool which turns true on button press and turns false once the attack completes. And you could add the bool logic to your button press so it only works if your attack is complete.

For example if you press button in OnGUI and it turns attackBool = true;

 bool attackBool;
 bool attackActiveBool;
 
 void Start()
 {
 //set animation Wrap Mode for the attack to "Once"
 animation["Attack"].wrapMode = WrapMode.Once;
 }
 
 void Update()
 {
 
 //after OnGUI() button press this will be true
 if (attackBool == true)
 {
 
 //start attack animation
 if (attackActiveBool == false)
 {
 gameObject.animation.Play("Attack");
 attackActiveBool = true;
 }
 
 //once the attack animation completes
 if(!animation.IsPlaying("Attack"))
 {
 attackBool = false;
 attackActiveBool = false;
 }
 }
 }

But for your specific problem I beleive Crossfade is messing things up for you. If you want to use an animation and gaurantee it plays the whole thing and looks correct visually you should probably use animation.Play() instead of animation.CrossFade().

I have always had trouble using Crossfade for anything important. While it may look much better the logic gets a little goofy especially if you are using Animation Events.

Maybe I don't fully understand it but I feel CrossFade needs better documentation or some game engine improvements to use it correctly for important game play type stuff.

You may need additional logic to ensure no other animations can possibly play when attackBool == true

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

20 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

Related Questions

Animation Stop and Stay 1 Answer

Animation problem in script 0 Answers

Walking animation has wrong rotation 0 Answers

Zooming animation doesn't work 1 Answer

Why is Animation Not Playing in Reverse? 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