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 manny003 · Jan 09, 2015 at 03:33 PM · animationjavascriptgameobjectanimationclip

How do I access the current playing animation clip of a gameObject?

More specifically, I need to check to ensure that the current "Pressed" animation clip of the Unity 4.6 Button has finished before I fire the onClick event.

I've found many posting about various techniques on how to check if an animation clip is still playing, wait for complete, etc. -- but they all make assumptions that I already have a handle to the animation/clip itself.

However, I have a more fundamental issue, given a gameObject (in this case, a UI Button game object), how do I traverse the object relationships, use GetComponents, etc. -- to get to what I need to do the check I want?

Everything I've tried has thrown an error. I am programming using UnityScript/Javascript.

Thanks, Manny

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 Mmmpies · Jan 09, 2015 at 09:15 PM 0
Share

I'm not 100% sure what your ai$$anonymous$$g for it's not clear if you're using the legacy animation or mecanim.

The most simple way is to record when the animation starts and check for the time it takes the animation to play then trigger the event. I do this for firing arrows, only fire if the animation has had time to reach a $$anonymous$$imum fire level.

Oh and if you get an answer mark it as correct and click thumbs up for comments that help. $$anonymous$$arma points don't overly bother me but you'll get more help if you take the trouble to simply click answered.

avatar image manny003 · Jan 10, 2015 at 12:44 AM 0
Share

What I'm trying to do is use the new Unity UI Button transition animation. I made a pulsate grow animation where once a button is clicked, it expands a bit and then shrinks back down to normal size.

What I've discovered, sadly, is that as cool as it is that Unity helps in creating the animation by automatically adding the controller, and assigning it to the button, etc -- it's still not a fully baked solution just yet. I've encountered a number of issues/shortco$$anonymous$$gs:

  1. There is no ready support for an onclick sound effect.

  2. There is no obvious way to specify that the animation be allowed to run its full cycle before firing the onclick event function.

  3. There are issues with rapid clicks causing issues with animations, etc.

So I'm trying to code my way around these feature gaps and quirks but what I'm slowly seeing is my code is beco$$anonymous$$g spaghetti. As soon as I think I've solved one issue another comes up.

I may have to abandon using the built in animation support altogether and try to come up with an alternate approach.

avatar image InvincibleCat · Jan 10, 2015 at 12:47 AM 0
Share

Did you look at my answer? By the way there are many ways to use animation to play sounds. Like having a script with a PlaySound method and call this method in your animation by adding a new animation event.\

Cheers

avatar image manny003 · Jan 10, 2015 at 03:03 AM 0
Share

Yes I saw your reply and I thank you for your efforts.

I ended up using the following code to get access to a gameObject's animation state data:

 var anim = myGameObject.GetComponent(Animator);
 var stateInfo : AnimatorStateInfo = anim.GetCurrentAnimatorStateInfo(0);

But I had to abandon that path for my code was beco$$anonymous$$g too convoluted. I realize that there is a way to get an animation to play a sound at the desired moment. What I had done was simply add an AudioSource component to my button in the Inspector, turn on AutoPlay and simply have the animation turn on the component at the start of the animation clip and off again at the end.

$$anonymous$$y larger point, though, was that I had wished that this was baked into the UI.Button a little better as to simplify the process a little bit more.

I'm not ungrateful for what Unity has provided thus far in the new UI system but I await the next revision to see what else they can improve upon.

avatar image InvincibleCat · Jan 10, 2015 at 03:07 AM 0
Share

$$anonymous$$y opinion is that it's really easy to just attached a simple script to your game object and use animation events ^^

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

27 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Enter Trigger, play animation(s) and sound FX 1 Answer

Enemy circles player instead of attacking. 1 Answer

Hit any gameobject, animation will play? 1 Answer

Animations cant be seen? 1 Answer

Setting keys in Animation Editor through Editor code 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