summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Test/ArmorSoldierScript.cs
blob: b6863a23744d9e5397f80787014fe458e832af4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ArmorSoldierScript : Avatar
{
    int Anim_HurtFront;

    private void Start()
    {
        base.Init();
        Anim_HurtFront = Animator.StringToHash("Hurt_Front");
    }

    private void OnAnimatorMove()
	{
		Animator animator = GetComponent<Animator>();

		// animator.deltaPosition和animator.deltaRotation是animator做的root motion后的结果
		// 在后面做一个硬性约束z=0,将角色限制在z=0平面上
		if (animator)
		{
			Vector3 position = transform.position;
			position.x += animator.deltaPosition.x;
			position.y += animator.deltaPosition.y;
			transform.position = position;

			// animation clip导入设置旋转一般上设置为baked inpose,不需要手动限制
			transform.rotation *= animator.deltaRotation;
		}
	}

    public void Hurt()
    {
        Animator animator = GetComponent<Animator>();
        animator.CrossFade(Anim_HurtFront, 0);
    }

    public override void OnHurt(HurtInfo hurtInfo)
    {
        base.OnHurt(hurtInfo);
        Hurt();
    }

}