-
Notifications
You must be signed in to change notification settings - Fork 0
/
Entity.cs
90 lines (83 loc) · 2.38 KB
/
Entity.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// use textmesh pro
using TMPro;
public abstract class Entity : MonoBehaviour
{
public GameObject animation;
public bool paused = false;
public abstract string targetTag { get; set; }
public virtual float speed {
get {
return 1.0f;
}
set { }
}
public virtual float dexterity {
get {
return 1.0f;
}
set { }
}
public virtual Vector2 aimDirection {
get {
return new Vector2(1, 0);
}
set { }
}
public float life = 10.0f;
public float maxLife = 10.0f;
public Coroutine getHitCoroutine = null;
public AttackSummoner currentAttackSummoner;
public ArrayList attackSummoners;
// Start is called before the first frame update
void Start()
{
}
public virtual IEnumerator GetHit(float damage)
{
// check if it has component SpriteRenderer
if (GetComponent<SpriteRenderer>() != null)
{
// flash red
GetComponent<SpriteRenderer>().color = Color.red;
yield return new WaitForSeconds(0.1f);
GetComponent<SpriteRenderer>().color = Color.white;
getHitCoroutine = null;
}
else{
// flash red the animation
animation.GetComponent<SpriteRenderer>().color = Color.red;
yield return new WaitForSeconds(0.1f);
animation.GetComponent<SpriteRenderer>().color = Color.white;
getHitCoroutine = null;
}
}
public virtual void TakeHit(float damage, float knockbakPower)
{
// move enemy in the opposite direction of the player
// transform.position = Vector3.MoveTowards(transform.position, player.transform.position, -knockbakPower*50 * Time.deltaTime / knockbakResistance);
// take damage
life -= damage;
if (life <= 0)
{
// die
Die();
}
else
{
// flash red
if (getHitCoroutine == null)
{
getHitCoroutine = StartCoroutine(GetHit(damage));
}
else
{
StopCoroutine(getHitCoroutine);
getHitCoroutine = StartCoroutine(GetHit(damage));
}
}
}
public abstract void Die();
}