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 Orloffyeah · Jun 30, 2015 at 05:57 PM · animationanimatorframestate

Determine in which frame is an Animation currently

Hi, the problem that I have encountered is that I want to know in what frame an animation is, since depending on it, when an object is killed a different animation should play so it makes sense. For example, if the enemy is looking up, when its killed it plays a different animation than when he is looking down. I've tried with CurrentAnimatorStateInfo but can't achieve the results I want. I´ve also tried a code found somewhere else, in which it recommends using this:

 ratio = GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).normalizedTime / GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).length;
 
 frame = ratio * (framesInAnimation);

in order to determine in which frame the animation is, but still I can't determine the current frame of an animation, any other ideas on how to approach this problem?

What I want to achieve is something like this:

 public void Death()
 {
 
 if(frame == 1)
 {
      animator.SetBool("Death1", true);
 }
 if(frame == 2)
 {
      animator.SetBool("Death2", true);
 }
 etc...
 }
 
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

2 Replies

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

Answer by GiyomuGames · Jul 01, 2015 at 12:44 AM

So you have a long animation during which the enemy is looking down, then up, etc. Something like that?

If so then the best way to do what you want to do is I believe to have 2 (or more) animations instead of 1. You should have 1 animation for each status of your enemy. Assuming your enemy is either looking down or up: you can create a first animation "enemy look down" with the first half of your sprites, and then "enemy look up" for the second half of your sprites. Then in your animator you make them loop (when "enemy look down" is finished it goes immediately to "enemy look up", when "enemy look up" is finished it goes immediately to "enemy look down"). In the game you won't be able to tell that there are actually 2 animations looping. Thanks to this you can then create a transition between each animation to your appropriate death animation ("look down death", "look up death" for example). When your "Death" boolean is true (no need for Death1 or Death2) it will trigger the suitable animation depending on the origin state.

I hope that helps.

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 Orloffyeah · Jul 01, 2015 at 04:55 PM 0
Share

It worked like a charm, cheers pal :)

avatar image
1

Answer by hnmikechan · Jun 30, 2015 at 06:51 PM

Can you enter in an event trigger in the animation clips timeline? You can choose the frames you want for the events. Then you can specify the method to check which death sequence you should play.

http://docs.unity3d.com/Manual/animeditor-AnimationEvents.html

Comment
Add comment · Show 3 · 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 Orloffyeah · Jun 30, 2015 at 08:27 PM 0
Share

I am not able to edit any of the animations in the Animation Window, it won't allow me to add animations to it. If it affects somehow, I created the animations by dragging multiple sprites into the scene, and the animation file was automatically generated.

avatar image hnmikechan · Jun 30, 2015 at 09:06 PM 0
Share

The animations were imported from another program like max or blender?

avatar image Orloffyeah · Jun 30, 2015 at 11:34 PM 0
Share

No, they where made like commented before, just drag & dropped the sprites into the scene.

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

23 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

Related Questions

Continuously Play Animation Forwards and Backwards with Mechanim 0 Answers

Animator.GetCurrentAnimatorStateInfo(0).IsName("FallOffBed") unexpectedly returns false 0 Answers

Can't Check If Animatorstate Is In Second Layer 1 Answer

Can an empty state in Animator cause performance issues? 1 Answer

Switch animation state while keeping animation timing 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