Article directory
1. Animation
1.1 Create Animation
- Select the object to be animated, open the Animation panel
and click Create to create the animation
1.2 Animation properties
2. Animator
2.1 Animator components
When we create an objectAnimationhour. An Animator has quietly appeared on the corresponding GameObject
2.2 Animation state
Each Animator Controller comes with three states: Any State, Entry and Exit.
- Any State
A special state representing any state. For example, if we want the character to be able to switch to the death state in any state, then Any State can help us do it. When you find that a state can jump from any state with the same conditions, then you can use Any State to simplify the transition relationship. - Entry state
Indicates the entry state of the state machine. By default, which animation the Animator component will play is determined by the Entry.
You can change the default state by right mouse button -> Set as Layer Default State in any state.
- Exit status (time-consuming Baidu)
2.3 State control parameters
Add state parameter:
Click the connection between the states, and you can set it in the Inspector window. You can add conditions under the Conditions column. The following figure shows that when the parameter
animPara is 0, the transition from Any State to New State will be executed.
2.4 Control state in the code
Animator ator = go1.GetComponent<Animator>();
ator.SetInteger("animPara", 1);
3. The code controls the play/pause/continue of the animation
- Replay
Animator.Play(state, layer, normalizedTime)
// 比如有一个叫“hit”的动画,在layer 0层中
animator.Play("hit", 0, 0f);
- Pause and resume playback
Animator
// 播放
animator.Play("ani_name");
// 暂停
animator.speed = 0;
// 继续播放
animator.speed = 1;
Animation
// 播放
animition.Play("ani_name");
// 暂停
animition["ani_name"].speed = 0;
// 继续播放
animition["ani_name"].speed = 1;