Tower defense game study notes 2, the animation effect when the money is not enough in the ui interface

game interface

insert image description here

Purpose, when creating a turret, if the remaining money is not enough to build the turret, the money will produce a flashing animation.

Step 1: Select the UI object that needs to be animated

insert image description here

Step 3: Click Animation or Ctrl+6 under the window

insert image description here

Step 4: Click create in the pop-up interface to create it under the corresponding folder.

insert image description here

The folder created here is as follows. After the creation, two such files will be generated. flicker is the name created, and Money is the name of the object that created the animation.

insert image description here

Step 5. After creating the animation based on the frame, double-click Money to open the Animator interface

insert image description here

Step 6. Operation on the Animator interface

Right-click create state > Empty to create an empty object and name it Empty

Right-click Entry > Make Transition and Set *** Default State to Empty.

Then use Make Transition to connect Empty and filcker to each other, as shown in the figure above.

Create a Filcker in the upper left corner

insert image description here

Click the line from Empty to filcker, and make the following settings on the left

insert image description here

Flicker does not need to be added to the line from filcker to Empty, and Has Exit Time remains selected (Has Exit Time means automatic execution)

The above is the setting in unity, and the following is the script part

Still open the BuildManager build management script and define an Animator attribute.

    //钱减少时的动画播放
    public Animator moneyAnimator;

Then there is a method to start the animation according to the Animator property where needed

	//TDOO 提示钱不够
	moneyAnimator.SetTrigger("Flicker");

The Flicker in the SetTrigger method is the parameters (parameters) added under Unity's Animator interface

Finally, don't forget to assign the UI object to the Animator property in unity

insert image description here

Guess you like

Origin blog.csdn.net/weixin_44923787/article/details/123102403