Skip to content

format

typescript
Animation.Play(name, mode)

class: Animation

description

Plays an animation clip named "name" directly without any blending or fading.

By using the Play method, you can play a pre-defined animation at runtime. This method can be used to trigger different actions of a character, such as walking, running, attacking, etc.

parameter

param_nametypedescription
namestringThe name of the animation clip.
modeAnimationPlayModeThe animation play mode. The default value is AnimationPlayMode.StopSameLayer.

reture

typedescription
booleanWhether the animation clip was played successfully.

code example

typescript
let obj = new GameObject();
let animation = obj.AddComponent<Animation>(Animation);
animation.Play("clip_name", AnimationPlayMode.StopAll);