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 /
This question was closed Feb 09, 2015 at 03:52 AM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
2
Question by FlashX · Feb 07, 2015 at 09:19 AM · c#animationif statementcheck

How to check if animation is playing? C#

hi all!

i'm having trouble here...

i'm trying to figure out if a specific animation is playing or not in the Animator, and if its not, then do something.

I also am trying to do it from a script that isnt attached to the animated geometry.

this is what I have but I cant get it working:

 //in public class Other : MonoBehaviour {
  Animator anim;
 
 
 //in an IEnumerator
 if(anim.animator.GetCurrentAnimatorStateInfo(0).IsName("Idle")){
     print("IDLE IS PLAYING");
 }
 
 
 //in void Start ()
 player = GameObject.Find("Character");
 anim = player.GetComponent<Animator>();


can anyone help me with some code that works?

thanks heaps!

:)

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

  • Sort: 
avatar image
6
Best Answer

Answer by meat5000 · Feb 09, 2015 at 03:39 AM

 (anim.animator.Get ETC


Drop the 'animator' and you are on to a winner.

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 FlashX · Feb 09, 2015 at 03:44 AM 0
Share

O$$anonymous$$G! meat500!!! You have made my day!! That has been plaguing me for days!! Thank you so much!!! :D

avatar image meat5000 ♦ · Feb 09, 2015 at 03:49 AM 0
Share

You are welcome.

Just like using 'gameObject' to reference the actual gameobject the script is on, using 'animator' references the Animator on the gameobject. When using the words this way, the editor does the linking for you so you don't need to include the declarations; it's done behind the scenes.

You provided your own reference (good practise)

 Animator anim

and linked it with GetComponent.

So you only need to use what you have defined :

 anim.GetCurrentAnimatorStateInfo(0)
avatar image FlashX · Feb 09, 2015 at 03:50 AM 0
Share

Thanks again bro! :)

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

Multiple Cars not working 1 Answer

Conflicting Animator SetTrigger 0 Answers

How to check if an object is rendered? 2 Answers

Distribute terrain in zones 3 Answers

How to add keyframe animation to an imported FBX. 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