[Super detailed] Unity combat mode (3) character blood loss processing + death animation processing

Blood loss treatment

Double-click the attack animation clip , open the Events area, right-click on the timeline, and select the appropriate frame, that is, we hope that a certain method will be executed at the moment the action is issued.

You can preview the effect of that frame through the animation preview area below. The blue vertical line is the frame we created.

Change the name to Attack and remember to Apply
It also means that the corresponding method name in our script is also Attack.
Write a corresponding Attack method in the ice script
Copy the health bar canvas to another character
Statement + health bar follow + drag
Add an attack clip to the character controller

+trigger, the same as the added Bool written before, named IsAttack
Click the transition line from idle state to attack state , add the IsAttack we just wrote in Conditions , and the condition is true
Check loopTime

In this case, we can use code to implement: animHb.SetTrigger("isAttack");
↓↓↓↓↓ The Attack method just written will be executed at the frame of the action. The blood loss is handled here ↓↓↓↓↓

Adjustment----Front hit

Idea: Turn to the opponent when attacking
Apply to Quaternion
Determine whether to attack + turn when the left button of the mouse is clicked, and not to attack when raised.

Death animation processing

It is the same as adding the number of frames above
+trigger
At this time, you can add a Dead method to the script to write Destroy characters and health bars.

Adjustment---- after character death

Guess you like

Origin blog.csdn.net/m0_74022070/article/details/130057652