|
Post by Legend on Sept 12, 2018 22:37:30 GMT
Hey I am looking for some help with the animator and yielding to it within an enumerator. IEnumerator playAnimation(IContainer game, GameAction action) { if (LocalPlayerFirst)
anim.Play("Local", 0, 0f);
else
anim.Play("Enemy", 0, 0f);
anim.enabled = true;
while (anim. isplaying) yield return null;
//need to do other code after its done
what i am trying to do is tell the animator to yield through - i tried yield return new waitforseconds(); but that doesnt appear to delay it - really it would be good to finish them move on - i am having trouble finding docs and articles that actually resolve this issue -
even tried
float continue_time = Time.time + anim.GetCurrentAnimatorClipInfo(0).Length;
while (Time.time < continue_time)
{
yield return null;
}
any links would be great and i can go through them
|
|
|
Post by Legend on Sept 13, 2018 5:58:42 GMT
Okay so did alot more research as it seems to be a fairly popular topic with alot of suggestions with very little actual confirmation of working - i was able to get something to work - instead in the animator - i searched through the animation clips of the controller and matched the string name of the clip i needed and got the length that way...for some reason the getcurrentanimatorclipinfo length i am guessing is returning a different length than what I expect.
|
|
|
Post by Admin on Sept 13, 2018 14:24:18 GMT
As a personal preference, I don't like working with the duration of a clip directly. If I remember correctly, I don't think it will work in scenarios where you may wish to add multipliers to animation speeds such as if a character is under a haste or slow game modifier. In the past I have used animation events instead, and had success. You could do something like have your animator yield until the animation event is triggered, and perhaps the animation event marks some sort of flag that you were using to yield based upon. docs.unity3d.com/Manual/animeditor-AnimationEvents.html
|
|
|
Post by Legend on Sept 13, 2018 15:35:48 GMT
I tried the event method first - but it seemed to have an issue with stopping at the end of the clip exactly - i may try it again - i thought it was something to do with how stop handled and it finished up at end of frame or something and my 48 fps for the clip didn't help - but might have been my code and how it was arranged - went through quite a bit of iterations so hard to remember now.
thanks for your insight as always Jon!
|
|