/
E_Movement.cs
74 lines (65 loc) · 1.76 KB
/
E_Movement.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
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class E_Movement : MonoBehaviour {
GameObject hero;
Transform h_Transform;
H_Health h_health;
NavMeshAgent e_nav;
bool startChasing = false;
Animator e_anim;
GameObject e_image;
void Start()
{
e_nav = GetComponent<NavMeshAgent>();
hero = GameObject.FindGameObjectWithTag("Hero");
h_Transform = hero.transform;
h_health = hero.GetComponent<H_Health>();
e_anim = GetComponent<Animator>();
e_image = GetComponentInChildren<Image>().gameObject;
e_image.SetActive(false);
}
void FixedUpdate()
{
if (!LevelState.levelManager.levelStart)
{
e_nav.SetDestination(transform.position);
e_anim.SetBool("isRunning", false);
return;
}
if (startChasing && h_health.currentHealth > 0)
{
e_nav.SetDestination(h_Transform.position);
e_anim.SetBool("isRunning", true);
}
else
{
e_anim.SetBool("isRunning", false);
e_nav.SetDestination(transform.position);
}
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject == hero)
{
startChasing = true;
e_image.SetActive(true);
}
}
void OnCollisionEnter(Collision other)
{
if (startChasing && other.gameObject.CompareTag("Player"))
{
//Debug.Log("Player Entered");
StartCoroutine(SlowDown());
}
}
IEnumerator SlowDown()
{
e_nav.speed = 10f;
e_anim.speed = 0.5f;
yield return new WaitForSeconds(3f);
e_nav.speed = 18f;
e_anim.speed = 1f;
}
}