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 Danicano · Jun 14, 2015 at 01:55 PM · mecanimanimationslagtransition

Animation when the key is down and second animation when the key is up

I'm trying to make an animation1 which starts when a key is held down and stays at its end until the same key is up. When that key is up a second animation2 starts. Also, if I press down and up the key the object performs the two animations one after the other. Also, if I press the key down when animations are performing, the animation1 mustn't start again (animation2 only starts when animation1 is over). The system I'm trying to implement is meant for a sword that when you hit a key down the sword performs a slash and stays at that position until the key is up and the sword performs a second slash that leads it to the original position.

What I've done so far:

Transitions amng the animations and an Idle state:

alt text

The script that controls everything:

     Animator anim;
 
     void Start () {
         anim = GetComponent<Animator> ();
     }
     
     void Update () {
         if (Input.GetKeyDown (KeyCode.Space) && anim.GetBool("condition1")==false)
             anim.SetBool("condition1",true);
         if (Input.GetKeyUp (KeyCode.Space) && anim.GetBool ("condition2") == false) {
             anim.SetBool ("condition2", true);
             anim.SetBool("condition1",false);
         }
         
     }
 
     public void Event1(){
         anim.SetBool ("condition1", false);
     }
     public void Event2(){
         anim.SetBool ("condition2", false);
     }

I've put events at the end of animation1 and animation2 which call Event1() and Event().

PROBLEMS: If I check Has Exit Time to all transitions and put all settings to 0 it works as expected but there are lags between animations and sometimes when I press down and up the key it does nothing and I have to press the key again. Where the lags come from? If I uncheck Has Exit Time boxes there are no lags but when the key is up animation won't finish and animation2 starts without animation1 being over. I'm stucked at this point.

I don't know if I explained myself well because English is not my native language, but I tried to give all the details that I know. I'm trying to understand all Mecanim system before trying to do more complex animations. Thanks.

captura-de-pantalla-2015-06-14-a-les-111753.png (26.2 kB)
Comment
Add comment
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

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

2 People are following this question.

avatar image avatar image

Related Questions

Mecanim empty state has unwanted delay 1 Answer

How to add animations to my rigged 3d model 3 Answers

Death animation and respawn? 0 Answers

Unity 5.2: Mecanim Transition Blending 1 Answer

How to stop mesh disappearing during Animator state transition blend time? 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