banner



How To Use Animations In Script In Unity

Unity has a function called Animator Controller, which is used to implement animation effects for characters and 3D models.

Animator Controller controls multiple blitheness clips. By using this function, y'all tin switch blitheness clips and combine different animations.

AnimatorController Settings

In this article, I volition innovate how to use Animator Controller to create a rotating cube animation.

Be aware that you lot need basic knowledge about the blitheness role beforehand, and so if you haven't read the '[Introduction to Unity] Learn Animation System' article however, please read this first.

  • 1 Open the Animator Controller
  • ii Creating an Blitheness
  • iii Create a State
  • 4 Role of Each State
    • 4.i Entry
    • 4.ii Whatever State
    • 4.3 Go out
  • 5 How to Use Animator Controller
    • 5.ane Looping the Animation
  • 6 Conclusion

Open the Animator Controller

Earlier starting, please create a Cube in a Scene.

You lot tin can go along the settings as a default.

Create a Cube

First, go to the Projection view and select「Create」→「Animator Controller」.

Creating an animation controller in the Projection view

A new file is created in the Assets binder. This is the Animator Controller file.

For this tutorial, I want to create an animation where the object just rotates, and then please change the Animator Controller's proper noun to 'Rotate'.

The created AnimatorController

Double click on the Animator Controller file. The Animator settings window will announced in the Scene.

Animator settings

Creating an Animation

Let's create a Rotate animation.

In the Projection view, right click and select「Create」→「Animation」.

Create an Animation prune

An blitheness clip volition be created in the Avails folder, and then change the file proper name to 'Cube Rotate'. Drag and drop the file into the Cube's Inspector window.

This process is needed because the file does not work on it's own, it needs to be attached to the object it affects (in this case, The Cube).

Adding an animation past drag and drop

An animation has been added to the Cube's Inspector window.

Animation added to the Inspector

Although the animation is gear up to the Cube object, the animation is still empty.

Nosotros need to add a rotation movement to the animation.

Click the Window menu, select Animation and open the Animation view.

Animation view

In the Animation view, select「Add together Property」→「Transform」→「Rotation」, and click the + button.

Add properties to Rotate

Every bit in the image below, a timeline volition be displayed. You lot modify the keyframe value of Rotation.y to one:00 to 360.

Settings to rotate in one case every second around the Y-axis

These settings brand the Cube rotate once (for 360 degrees) around the Y-axis in i 2d.

Running the Scene looks like the animation below.

The Cube rotates simply one time

Equally designed, the Cube rotates once around the Y-axis. But the animation stops after ane rotation.(The to a higher place is a GIF epitome, so it will rotate continuously)

Create a State

Adjacent, I will explain how to use the Animator Controller.

Right click in the Animator window, and select「Create Land」→「Empty」.

Select Empty

A rectangle called 'New State' has been created.

New Land is created

The rectangles in the Animator window are called  'States', which includes 'New State'.

A State is a role that can store and ready parameters for animation clips. By adjusting the settings of each State y'all can alter the animation'south characteristic.

Currently, an arrow has been drawn from the 'Entry' Country and heads toward the 'New State'. This arrow is called a Transition.

A transition is used to define the execution order of animations. In the to a higher place image, the 'Entry' blitheness runs first and then the 'New Land' animation runs second.

Part of Each Land

I will explain the basic roles of each default State.

Entry

The Entry Country is the starting time State that is called and transitions start from here.

You lot demand to set a transition from Entry to the animation if you want to run it first.

Entry

Any State

The Whatsoever State functions to transition from Country to Country.

Any State

And then, if you set a transition equally in the image beneath, then you lot can set whatsoever transitions you want to.

Any transitions can be set

Exit

If you transition to the Leave Country, the transition resets to the Entry State.

Exit

So, if you set the terminal transition to the Get out State, then you can loop your animations.

How to Use Animator Controller

Once we accept learned nearly each Land, allow's select the 'New State' we created in the previous footstep and alter the proper name to 'Cube Rotate'.

Changing the State proper name

Looping the Animation

Side by side, let's set a loop for the animation by editing the State settings.

Right click the 'Cube Rotate' State, so click 'Make Transition'.

Select Make Transition

A white pointer will emerge. Adhere this arrow to the 'Exit' State.

Transition to the Leave Country

The transition will render (reset) to the Entry State subsequently the Exit State. The animation volition loop with this setting.

Run the Scene and check the animation.

Looping Rotate blitheness

You lot tin see the animation is looping at present.

Conclusion

In this tutorial, I introduced how to set an blitheness in Unity.

If an animation looks complicated, then information technology is because there are many objects included with many associated movements and transitions.

I hope yous make practiced use of the Animator Controller in Unity.

Source: https://styly.cc/tips/animator_controller/

Posted by: shieldsyourst39.blogspot.com

0 Response to "How To Use Animations In Script In Unity"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel