-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathAttack.cs
More file actions
100 lines (83 loc) · 2.37 KB
/
Attack.cs
File metadata and controls
100 lines (83 loc) · 2.37 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Attack : MonoBehaviour {
public string attackName;
public int damage = 1;
public AudioResource attackLandSound;
[Range(0, 2f)]
public float cameraShakeIntensity = .1f;
[Range(0, 2f)]
public float cameraShakeTime = 0.1f;
public bool selfKnockBack = false;
public Vector2 selfKnockBackVector = Vector2.zero;
public bool forceX = false;
public GameObject hitmarker;
public bool flipHitmarker = false;
[HideInInspector]
public List<string> attackedTags;
public Entity attackerParent;
public float stunLength = 0.2f;
public bool knockBack = true;
public Vector2 knockbackVector = Vector2.zero;
public bool knockbackAway = false;
public bool inheritMomentum = false;
public bool instakill = false;
protected Rigidbody2D rb2d;
void Start() {
if (attackerParent == null) {
attackerParent = GetComponentInParent<Entity>();
}
rb2d = attackerParent.GetComponent<Rigidbody2D>();
}
public virtual int GetDamage() {
return this.damage;
}
public void OnAttackLand(Entity victim, Hurtbox hurtbox) {
ExtendedAttackLand(victim);
if (attackLandSound && !hurtbox.overrideHitSound) {
SoundManager.PlayIfClose(attackLandSound, victim.gameObject);
}
Animator a;
if ((a = attackerParent.GetComponent<Animator>()) != null) {
a.SetTrigger("AttackLand");
}
}
public virtual void MakeHitmarker(Transform pos) {
GameObject h = Instantiate(hitmarker, pos);
h.transform.position = pos.position;
}
virtual protected void OnTriggerEnter2D(Collider2D otherCol) {
Hurtbox hurtbox = otherCol.GetComponent<Hurtbox>();
if (!hurtbox || !ExtendedAttackCheck(hurtbox)) {
return;
}
Entity entity = hurtbox.GetParent();
if (attackedTags.Contains(hurtbox.gameObject.tag)) {
if (hurtbox.OnHit(this)) {
OnAttackLand(entity, hurtbox);
}
}
}
public virtual Vector2 GetKnockback() {
Vector2 baseKnockback = new Vector2(
x:knockbackVector.x * attackerParent.ForwardScalar(),
y:knockbackVector.y
);
if (inheritMomentum) {
baseKnockback += rb2d.velocity;
}
return baseKnockback;
}
public float GetStunLength() {
return this.stunLength;
}
public virtual bool ExtendedAttackCheck(Hurtbox hurtbox) {
if (hurtbox == null) {
return false;
}
return !hurtbox.GetParent().invincible;
}
public virtual void ExtendedAttackLand(Entity e) {
}
}