-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pet_Healer.cs
53 lines (50 loc) · 1.62 KB
/
Pet_Healer.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Pet_Healer : PetController
{
[SerializeField] float actionsTakenEverySec = 1f;
[SerializeField] float percentToHeal = 3f;
[SerializeField] float hpToGoFix = 25f;
[SerializeField] float attackDamage = 10f;
// Start is called before the first frame update
public override void Start()
{
base.Start();
Invoke("LateStart", actionsTakenEverySec);
}
void LateStart()
{
StartCoroutine(CalcNextAction());
}
IEnumerator CalcNextAction()
{
while (true)
{
gameObject.GetComponent<MeshRenderer>().material.color = Color.blue;
if (PlayerNeedsFix(hpToGoFix))
{
StartCoroutine(GoToTarget(player.transform));
yield return new WaitWhile(()=> !atTarget);
HealPlayer(percentToHeal);
}
else
{
target = GetTarget();
if (target != null)
{
StartCoroutine(GoToTarget(target));
yield return new WaitWhile(() => !atTarget);
MelleeAttackEnemy(attackDamage);
}
else
{
StartCoroutine(GoToTarget(player.transform));
yield return new WaitWhile(() => !atTarget);
}
}
atTarget = false;
yield return new WaitForSeconds(actionsTakenEverySec);
}
}
}