• 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 KMKxJOEY1 · Mar 27, 2013 at 04:08 PM · animationtimespeedclampstate

Clamp animation to a certain amount of time?

hey guys, finally getting back into unity. I've been laying down the framework code for my FPS game, and i was wanting the reload times to be easily customizable. So far it works just fine, but now that I've implemented animation, the animation finishes before the reload does (the gun is idling but unusable until the reload time is up). I've tried messing with the speed, but i cant seem to get it right. I was hoping there was a way to make the animation play over a certain amount of time.

Thanks, Joey

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

Answer by Benproductions1 · Mar 28, 2013 at 12:10 AM

Speed is the right thing to change, heres how:

 //Just for typecasting
 var reloadTime:float;
 var animState:AnimationState;
 
 //Now for setting the speed
 animState.speed = reloadTime / animState.length;

All I did was set the speed to the multiplier the animations length needs to become the reload time (If that makes much sense)

Hope this helps,

Benproductions1

Comment
Add comment · Show 2 · 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 KMKxJOEY1 · Mar 28, 2013 at 01:30 AM 0
Share

Oh thanks it does, i was doing 1 / reloadtime :p stupid of me. had to make it fit in to my weaponinfo class, but made it work, thanks very much. I'm learning C# so for any of you guys who see this:

 public float reloadTime;
 public AnimationState animState;
 
 animState.speed = reloadTime / animState.length;

oh i didnt realize how similar they were lol just the way the variables are declared

Joey

avatar image KMKxJOEY1 · Mar 28, 2013 at 01:52 AM 0
Share

OH WAIT almost forgot to mention, you flipped it The correct speed is actually the animState length / reloadTime lol :3

Joey

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

11 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

Related Questions

Animation Stop and Stay 1 Answer

Play whole animation over specified time via script 1 Answer

[Solved] Reverse animation help 2 Answers

animation to play faster over time 2 Answers

Mecanim - changing animation clip speed, through script? 4 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