Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 MiniNinjaah · Oct 05, 2015 at 05:06 PM · c#animation2dbooleananimationevent

Keep boolean true whilst playing animation, then false

I have a little chunk of code within the Update function in order to detect the "Fire1" button/key being pressed. My code is as follows:

 public bool Kicking;
 void Update (){
     anim.SetBool ("Kicking", Kicking);
     if (Input.GetButtonDown ("Fire1")) {
         Kicking = true;
     }
 }

I use 'Kicking' as a condition for the animation to occur alt text

This causes the animation to be toggled upon using the "Fire1" input; however I am wanting to falsify the Boolean 'Kicking' directly after the animation has finished. ( I am going to be using this to check if the player is mid-kick when colliding with an object)

My initial thoughts on approaching this was to use the animation events. Upon adding the Player.Kicking Boolean as a property and making the Boolean true and false in the right places (beginning and end), I realised that the animation no longer plays, even if I don't modify anything at all. The Boolean is still modified to true but the animation does not initiate.

I'm not sure as to how effective it would be to wait for the animation to finish within the player script as I'll be using it for other things, any help will be greatly appreciated.

pvrjgmd.png (29.8 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by meat5000 · Oct 05, 2015 at 05:37 PM

Detect the currently playing clip

anim.GetCurrentAnimatorStateInfo(0).IsName("MyAnimationName") //or something to that effect

 if(!anim.GetCurrentAnimatorStateInfo(0).IsName("Kicking"))
 {
     anim.SetBool("Kicking", false);
 }

Something like that. Its crude.

I would add an exit time parameter.

Comment
Add comment · Show 1 · 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 Edin221Baker · Jul 14, 2017 at 06:46 AM 0
Share

Thanks a lot!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Set boolean to false when animation changes? 1 Answer

How to make an animation play after releasing key? 1 Answer

Animation not at correct position W/Video 0 Answers

Animation Not Playing - VideoExplanation 2 Answers

How do I know when an object is going under a Platform Effector 2D object? 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