0
\$\begingroup\$

‏‏‎

Currently, I have a script; more specifically for weapons. It handles animations, and the animations are being played and then stopped (once they're finished) by co-routines. I have variables for how long certain animations are (in frames), which are designated at the beginning of the script. I then take that and divide it by the frame rate they were animated in, for the co-routine's waitForSeconds. The problem is that for each weapon, I have to manually input how long each of their usually 13 animations is in the inspector.

‏‏‎

It'd be a lot easier if I could take the animation component that is being played, and have the script figure out how long it is, convert it to an integer, and use that for the waitForSeconds. I've looked around for this before (and just did again), but nothing has worked. If anyone needs me to clarify something, please let me know.

\$\endgroup\$
  • 1
    \$\begingroup\$ Why do you need to convert to an integer? WaitForSeconds handles floats just fine, so you could use AnimationClip.length directly, no conversion required. \$\endgroup\$ – DMGregory Nov 25 '18 at 0:06
  • \$\begingroup\$ I've tried that before, but it's never worked. I just tried it again, and (probably because I'm using a different animation handling system) it worked, thanks! \$\endgroup\$ – ThriftyDonut Nov 26 '18 at 22:44
0
\$\begingroup\$

As DMGregory said, you can just use AnimationClip.length. It's a float, but WaitForSectonds handles floats just fine. The reason it hadn't worked for me before was that I was using a different animation handling system and because I wasn't using the "AnimationClip.length" function properly.

\$\endgroup\$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.