how to know please when any animation has finished being played (it means when to know the end of an animation) to be able to realize other things consequently at the end of the animation
but I’m talking about source code to implement as soon as the animation has finished being played and not checking whether an animation is being executed or not,
for example in my case I would like to check if the animation of player failure has finish being played , to be able to reload and restart the level again,
Hi all, bit late to the party, but just cooked this up for a client. It will call OnAnimationStopped() using System.Action once the animation has… stopped. I hope it helps some people, I personally think it’s the cleanest solution for my purposes at least.
using System;
using System.Collections;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour {
public string animClipNameToPlay; //AnimationClip must exist in _anim component
Animation _anim;
void Start()
{
_anim = GetComponent<Animation>();
PlayAndWaitForStop(animClipNameToPlay);
}
protected void OnAnimationStopped() {
Debug.Log("Animation stopped playing.");
}
public void PlayAndWaitForStop (string animClipName) {
_anim.Play(animClipName);
StartCoroutine(Listener_AnimationStopped(_anim, delegate {OnAnimationStopped();}));
}
public IEnumerator Listener_AnimationStopped(Animation a, Action callback) {
while (a.isPlaying) {
yield return null;
}
callback();
}
}