Animator anim;
void Start()
{
anim = GetComponent<Animator> ();
}
IEnumerator WaitForAnim(Animator anim)
{
while (GetComponent<Animation>().isPlaying == true)
{
yield return new WaitForSeconds (1);
}
}
I essentially want my animation to play without being interrupted but I can’t get any further then this…
Note : This isn’t the full script but this is the part where the problem is.
What line is the actual error on because this isn’t where the problem lies. WaitForAnim takes 1 argument (anim) but you’ve used it—somewhere—without placing an anim parameter.
WaitForAnim takes 0 arguments means you are calling the Coroutine without placing a variable for the anim parameter
StartCoroutine( WaitForAnim() );
should be
StartCoroutine( WaitForAnim( animator ) );
I changed the variable anim to animator because your argument is also named anim.
Not sure if this is just a snippet because I don’t see the anim parameter being used inside the coroutine. Instead of using GetComponent why not reference the animation component instead?
Animator anim;
void Start()
{
anim = GetComponent<Animator> ();
}
IEnumerator WaitForAnim(Animator anim)
{
while (GetComponent<Animation>().isPlaying == true)
{
yield return new WaitForSeconds (1);
}
}
to this:
Animator animator;
Animation animation;
void Start()
{
animator = GetComponent<Animator>();
animation = GetComponent<Animation>();
}
IEnumerator WaitForAnim( Animator curAnimator, Animation curAnimation )
{
while ( curAnimation.isPlaying )
{
yield return new WaitForSeconds( 1 );
}
}
Now, you have to call the coroutine differently:
StartCoroutine( WaitForAnim( animator, animation ) );
Also, waiting for a second each check may result in waiting well after the animation is finshed. May be better to wait every frame instead…