End of Animation

Hello, I have this animation right, and when it finishes I want it to load a scene. So for example I have my camera… when a certain button is clicked, the camera moves behind the wall where you only see black. Now when the animation on the camera finishes I would like it to send me to, for example “Scene X”.

Thanks!

Here are some animation extensions that I wrote for a project to do basically what you’re asking, as well as things as callbacks for OnUpdate, a delay before the animation is played, etc.

using UnityEngine;
using System;
using System.Collections;

/* Animation Extensions, Written by DSK
 * 
 * Used to extend functionality of the Unity Animation Class by way of CoRoutine
 * 
 */
public static class AnimationExtensions {
	
    public static IEnumerator PlayWithOptions(this Animation animation, string animName, Action onComplete)
    {
        animation.Play(animName);

        while (animation.isPlaying) { yield return null; }

        onComplete();
    }

    public static IEnumerator PlayWithOptions(this Animation animation, string animName, float delay, Action onComplete)
    {
        yield return new WaitForSeconds(delay);

        animation.Play(animName);

        while (animation.isPlaying) { yield return null; }

        onComplete();
    }

    public static IEnumerator PlayWithOptions(this Animation animation, string animName, Action onUpdate, Action onComplete)
    {
        animation.Play(animName);

        while (animation.isPlaying)
        {
            onUpdate();
            yield return null;
        }

        onComplete();
    }

    public static IEnumerator PlayWithOptions(this Animation animation, string animName, float delay, Action onUpdate, Action onComplete)
    {
        yield return new WaitForSeconds(delay);

        animation.Play(animName);

        while (animation.isPlaying)
        {
            onUpdate();
            yield return null;
        }

        onComplete();
    }
}

These functions are extending the Unity Animation class. For use, you would do something like:

StartCoroutine( gameObject.animation.PlayWithOptions( 
				animToPlay,
				() => 
				{ 
					Debug.Log( "ANIMATION FINISHED, LOADING SCENE X" );
                                    Application.LoadLevel( "SceneX" );
				}
				)
			);