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 Cobradabest · Jan 01, 2013 at 11:37 PM · c#animationanimatormechanim

How can I get the legnth of an animation? (Mechanim Animator/C#)

I'm making a First Person Shooter, and I'm currently trying to get my gun to reload, but I want to make the game wait until the reload animation has finished before the player can shoot again, I'm having trouble with this.

I am using the Mechanim Animator to do my animations, but all the solutions I see use the regular animation component.

I would think that you use "WaitForSeconds", the problem is, I don't have the value for the WaitForSeconds to wait for.

So how would I get the legnth of an animation when I'm using the mechanim animator? Preferably in C#.

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
0
Best Answer

Answer by Lovrenc · Jan 01, 2013 at 11:45 PM

I dont know wheather you can get animation lenght, but you dont really need to know it. You should have different animation/gameplay states. Eg. (ready, reloading, jumping,...).

 static int reloading = Animator.StringToHash("Base.Reloading");
 //Base - layer name; Reloading - animator state name

 

Then based on your animator state you decide wheather you can shoot or not. Animator will make shure your state gets to ready after reloading animation is finnished (exit-time).

I would weapon animations on separate layer than movement etc.

 Animator anim;
 void Start (){
     anim = GetComponent<Animator>();               
 }
 
 void FixedUpdate ()
 {
     currentBaseState = anim.GetCurrentAnimatorStateInfo(0); //if your stuff is on 1st layer
 
     if (currentBaseState.nameHash == reloading){
          //CANNOT SHOOT NOW
     }
 }
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 Cobradabest · Jan 02, 2013 at 02:05 AM 0
Share

Yeah but the problem is with the way I coded it, I need to know the legnth to tell the game how long to keep the realoding boolean as true.

avatar image Lovrenc · Jan 02, 2013 at 02:08 AM 0
Share

Sorry, i dont know about that nor was i able to find solution on the web.

avatar image Cobradabest · Jan 02, 2013 at 02:09 AM 0
Share

That's okay, I have made a temporary solution, thanks anyway.

avatar image
0

Answer by Ouss · Oct 20, 2013 at 12:17 PM

Hello, to get the length of the current state: yourAnimatorVariable.GetCurrentAnimatorStateInfo(0).length

0 if it the first layer, 1 if it's the second, etc

Comment
Add comment · 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

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

10 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

Related Questions

Mecanim animation 1 Answer

Controlling value of blend parameter via script 0 Answers

Animation component in Unity 4.3 doesn't work? 2 Answers

Distribute terrain in zones 3 Answers

Running animation 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