[Basics of Unity] 4. Animation

 [Basics of Unity] 4. Animation

        Hello everyone, I am Lampard~~
        Welcome to the Unity basic series blog. The knowledge I learned comes from Teacher Afa at Station B~Thank you 

 (1) Unity animation editor

(1) Animation component

    This time we are going to learn how to edit an animation in the unity editor. The component used is Animation, so what is the Animation component?

The Animation component in Unity is a component used to control the animation of game objects. The Animation component allows developers to create and edit object animations, as well as control the playback and pause of animations at runtime.

The Animation component has the following main properties and methods:

- Clip: Represents an animation clip, that is, a specific animation clip. Each animation clip contains a series of keyframes to define the state changes of the object during the animation.

- PlayAutomatically: When set to true, the animation will automatically play when the game object is enabled; when set to false, you need to call the Play() method through code to manually start animation playback.

- WrapMode: Define the animation loop mode, including Once (played only once), Loop (looped playback), PingPong (round-trip playback), etc.

- CrossFade: Use the fade-in and fade-out method to switch to the specified animation clip for smooth transition.

- Stop: Stop the currently playing animation and reset it to the starting state.

- Play: Play the currently set animation clip.

- Pause: Pause the currently playing animation and continue playing by calling the Play() method.

In addition to the above properties and methods, the Animation component also provides some callback functions, such as AnimationClip event, AnimationEvent, etc. , for executing custom logic during animation playback.

    Ok, I roughly know that much, so let’s start making the first animation~

(2) Create Animation Clip

    We just learned that Unity's Animation uses Clips to represent animation clips , that is, specific animation clips. Each animation clip contains a series of keyframes to define the state changes of the object during the animation.

    So let’s create an Animation Clip now. First of all, animation is also a resource, so we need to create a directory in Assets to save it.

    Then we only need to right-click create and select the Animation option. You can rename it normally.

    As for mounting, it is also very simple. We only need to drag it to the object we want to mount. Let’s select the rectangle created in the last article. Unity will help us select an Animation component by default to mount the clip.

(3) Animation editing

    At this point, we have successfully attached animation to this rectangle with rust material, and we were pleasantly surprised by the results! Nothing...

    Don't panic, this is actually normal, because we haven't edited this animation yet. Next we will open the animation editor to achieve the desired effect.

    We can select the Animation option in the Window menu bar, and then we can open the animation editor. We can put this tab in the Game window for easy editing.

    Let's take a look at this editor. In the upper left corner is a row of buttons that control playback, editing, and recording , which can be used to test the current animation effect. There is an Add Property button in the lower left corner . We can select the desired property for animation editing. On the right It is something like a timeline . It is used to record the animation frames we edited.

(2) The first animation

(1) Select animation components

    We can understand that an object animation means that some properties of some components of the object have changed from the starting moment to the ending moment.

    Click Add Property to select the component we want to change. For example, below we add the Position property of the transform component.

(2) Animation frame

    The right side of the Animation editor is where we control animation frames. The digital scale above it represents the frame . We can see that there is a 0th frame by default to record the initial Position information of the object.

    If we want to realize the animation of the position of this rectangle from Y=0 to Y=3 from frame 0 to frame 30, we need to design it in three steps:

    First, we need to click the red circle button to put the animation editor into the editing state. Editing will not take effect unless you click it.

    Then we need to adjust the Y-axis position of the object at frame 0 to ensure that it is at 0. We can adjust its Y-axis position by dragging the green axis in the Scene, but it is more recommended to adjust it directly in the inspector panel to be more accurate.

    Finally, we need to create an animation frame of frame 30. The way to create it is to click on the number axis 30, right-click the Add key, and then select this and wait for 30 frames, and adjust the positionY value of the object to 3

        At this point we click the play button of the animation editor to see the effect

(3) Add multiple attributes

    We humans can sing and dance at the same time, and Unity’s animation can also rotate while rising.

    How to do it? We only need to click Add Property again, select the Rotation property , set the selection angle to 0 at frame 0, and set it to 360 degrees at frame 30 to make a full circle.

    Take a look at the effect:

(3) Routine operations

(1) Delete operation

    We added a frame before, so how to delete this frame? Just select the frame you want to delete on the timeline, right-click and select the Delete Keys option.

    What if you want to delete an affected attribute? For example, if I don’t want it to rotate while going up, but just want it to rotate alone, I only need to select the property that I want to delete on the left side of the Animation editor and click Remove Property.

(2) Batch selection

    If we want to select multiple keyframes in batches, we can use the left mouse button to select the frame information we want to operate.

    You can also hold down shift/ctrl on the keyboard and click to make multiple selections

Okay, that’s it for today, thanks for reading! ! !
Like and follow! ! !

Guess you like

Origin blog.csdn.net/cooclc/article/details/132930347