-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqfHitEffect.cs
68 lines (54 loc) · 1.42 KB
/
qfHitEffect.cs
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#if SEALED
using UnityEngine;
using System.Collections;
/// <summary>
/// 通用打击特效
/// </summary>
[RequireComponent(typeof(Animator))]
public class qfHitEffect : MonoBehaviour
{
public static string ON_HIT_KEY = "onHit";
public static string ON_DEFEND_KEY = "onDefendBlock";
public bool DebugOn = false;
private Animator _animator;
private nsHitPause _hitPause;
private Vector3 _size;
public void OnHit(Collider2D col, Vector3 pos)
{
UpdateBound(col, pos);
Debug.DrawLine(pos, col.transform.parent.position, Color.yellow, 5.0f);
_animator.Play(ON_HIT_KEY, 0, 0f);
// 击中位置到攻击者重心划线,作为旋转角度。攻击者重心为原点
if (pos.y < col.bounds.center.y)
transform.localRotation = Quaternion.Euler(0, 0, 45);
else
transform.localRotation = Quaternion.Euler(0, 0, -45);
_hitPause.ShowHitPause();
}
public void OnDefend(Collider2D col, Vector3 pos)
{
UpdateBound(col, pos);
_animator.Play(ON_DEFEND_KEY, 0, 0f);
}
void UpdateBound(Collider2D col, Vector3 pos)
{
transform.position = pos;
_size = col.bounds.size;
}
void Start()
{
_animator = GetComponent<Animator>();
_hitPause = GetComponent<nsHitPause>();
}
void OnDrawGizmos()
{
if (!DebugOn)
return;
if (_animator != null && _animator.GetCurrentAnimatorStateInfo(0).IsName(ON_HIT_KEY))
{
Gizmos.color = Color.red;
Gizmos.DrawWireCube(transform.position, _size);
}
}
}
#endif