- Home /
Gun - Reloading time and reloading animation connected ?
Hello I have a small question regarding animations and Times.
Lets say i have a gun ( created in Blender ) and i have animated it in Unity ( Unity animation window ) and in my script I am calling the reload function.
My question is if animation created in unity has lenght of 0.758 how could I turn it into the waitForsecond time without needing to create a new variable,assigning number in the inspector and testing how it works.
//Add ammo
//yield return new waitForSeconds(reloadingTime //10 seconds or different depending on the animation //)
//Do something
Answer by TSI25 · Oct 26, 2017 at 03:31 PM
if you get a reference to the animation clip you can get the length of the animation clip, and wait for that duration. check out documentation for that here .
The only other way to go that I can think of would be to add animation events to the animation clip, and then when you are playing it you can listen for those events and not actually call the function to reload until that event fires (then you dont even need a coroutine) but some people think that approach can get a little messy and I tend to agree
Your answer
![](https://koobas.hobune.stream/wayback/20220612141911im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Yielding for a changing amount of time? 2 Answers
Ideas for Animating while Paused? 9 Answers
30 Objects all firing at exactly the same time and not randomly 1 Answer
WaitForSeconds() Is not working. 5 Answers
how to stop object before GO writes 1 Answer