EnemyController.cs
1.09 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class EnemyController : MonoBehaviour {
private NavMeshAgent _agent;
public Player target;
public ScaleUpGameManager gameManager;
Vector3 StartPosition;
// Use this for initialization
void Awake()
{
StartPosition = gameObject.transform.position;
Debug.Log("Enemy Position: " + StartPosition);
target = GameObject.Find("Player").GetComponent<Player>();
}
void Start ()
{
_agent = GetComponent<NavMeshAgent>();
gameManager = FindObjectOfType<ScaleUpGameManager>();
}
// Update is called once per frame
void Update ()
{
_agent.destination = target.gameObject.transform.position;
}
public void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.tag == "Player")
{
gameManager.GameOver();
}
}
public void RestartEnemy()
{
gameObject.SetActive(true);
gameObject.transform.position = StartPosition;
}
}