-
Notifications
You must be signed in to change notification settings - Fork 1
/
EnemyController.cs
57 lines (48 loc) · 1.36 KB
/
EnemyController.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class EnemyController : GazePointer
{
public GameObject particleEffect;
public Animator enemyModel;
public float speed;
Vector3 endPos;
BulletSpawner bulletSpawner;
// Start is called before the first frame update
void Start()
{
endPos = 1.5f * (transform.position - Vector3.zero).normalized;
bulletSpawner = GameObject.FindObjectOfType<BulletSpawner>();
}
// Update is called once per frame
void Update()
{
transform.position = Vector3.Lerp(transform.position, endPos, speed * Time.deltaTime);
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
Attack();
else if(other.CompareTag("Enemy"))
Death();
}
public override void OnPointerDown(PointerEventData eventData)
{
base.OnPointerDown(eventData);
bulletSpawner.ShootBullet();
//Death();
}
public void Death()
{
particleEffect.SetActive(true);
particleEffect.transform.SetParent(null);
Destroy(gameObject);
PlayerManager.currentScore += 100;
}
public void Attack()
{
enemyModel.SetTrigger("attack");
PlayerManager.playerHealth -= 0.2f;
}
}