Unity animation system (Animation, Animator, Timeline)

1. Animation

1.1 Create Animation

  1. Select the object to be animated, open the Animation panel
    insert image description here
    insert image description here
    and click Create to create the animation
    insert image description here

1.2 Animation properties

insert image description here

2. Animator

2.1 Animator components

When we create an objectAnimationhour. An Animator has quietly appeared on the corresponding GameObject
insert image description here

2.2 Animation state

Each Animator Controller comes with three states: Any State, Entry and Exit.

  1. 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.
  2. Entry state
    Indicates the entry state of the state machine. By default, which animation the Animator component will play is determined by the Entry.
    insert image description here
    You can change the default state by right mouse button -> Set as Layer Default State in any state.
    insert image description here
  3. Exit status (time-consuming Baidu)

2.3 State control parameters

Add state parameter:
insert image description here

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.
insert image description here

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

  1. Replay
Animator.Play(state, layer, normalizedTime)	
// 比如有一个叫“hit”的动画,在layer 0层中
animator.Play("hit", 0, 0f);
  1. 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;

Guess you like

Origin blog.csdn.net/weixin_45136016/article/details/128199063