Select your preferred scripting language. All code snippets will be displayed in this language.
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
ClosePlays animation without any blending.
Play() will start animation with name animation
, or play the default animation.
The animation will be played abruptly without any blending.
// Plays the default animation animation.Play();
using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { void Example() { animation.Play(); } }
import UnityEngine import System.Collections public class ExampleClass(MonoBehaviour): def Example() as void: animation.Play()
For a specific animation, you can call the animation with play as well.
// Plays the walk animation - stops all other animations in the same layer animation.Play("walk"); // Plays the walk animation - stops all other animations animation.Play("walk", PlayMode.StopAll);
using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { void Example() { animation.Play("walk"); animation.Play("walk", PlayMode.StopAll); } }
import UnityEngine import System.Collections public class ExampleClass(MonoBehaviour): def Example() as void: animation.Play('walk') animation.Play('walk', PlayMode.StopAll)