-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemyMiniMissile.cs
More file actions
117 lines (110 loc) · 3.27 KB
/
EnemyMiniMissile.cs
File metadata and controls
117 lines (110 loc) · 3.27 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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyMiniMissile : MonoBehaviour
{
[SerializeField]
private float _speed = 80f;
[SerializeField]
private GameObject _explosion;
private Player player;
private float health;
private float maxHealth = 100f;
private void Start()
{
player = GameObject.Find("Player").GetComponent<Player>();
if(player == null)
{
Debug.LogError("Player is null in Enemy Mini Missile script");
}
}
void Update()
{
int TotalCP = PlayerPrefs.GetInt("TotalCP");
if (TotalCP < 10)
{
transform.Translate(Vector3.right * _speed * Time.deltaTime);
}
else if (TotalCP >= 10 && TotalCP <= 20)
{
transform.Translate(Vector3.right * (_speed + 44) * Time.deltaTime);
}
else if (TotalCP >= 20 && TotalCP <= 30)
{
transform.Translate(Vector3.right * (_speed + 88) * Time.deltaTime);
}
else if (TotalCP >= 30)
{
transform.Translate(Vector3.right * (_speed + 132) * Time.deltaTime);
}
}
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
Instantiate(_explosion, transform.position, Quaternion.identity);
int TotalCP = PlayerPrefs.GetInt("TotalCP");
if(TotalCP < 10)
{
player.ReduceHealth(5);
}
else if (TotalCP >= 10 && TotalCP < 20)
{
player.ReduceHealth(10);
}
else if (TotalCP >= 20 && TotalCP < 30)
{
player.ReduceHealth(20);
}
else if (TotalCP >= 30 && TotalCP < 60)
{
player.ReduceHealth(30);
}
else if (TotalCP >= 60 && TotalCP < 100)
{
player.ReduceHealth(40);
}
else if (TotalCP >= 100)
{
player.ReduceHealth(50);
}
player._damage.SetActive(true);
}
if (other.tag == "Asteroid")
{
other.gameObject.GetComponent<Asteroid>().ReduceHealth(5f);
Instantiate(_explosion, transform.position, Quaternion.identity);
Destroy(this.gameObject);
}
if(other.tag == "Missile")
{
Instantiate(_explosion, transform.position, Quaternion.identity);
Destroy(this.gameObject);
}
if (other.tag == "Laser")
{
Instantiate(_explosion, transform.position, Quaternion.identity);
Destroy(this.gameObject);
}
}
public void ReduceHealth(float val)
{
if (health <= 100 && health > 0)
{
health -= val;
}
else if (health <= 0)
{
Instantiate(_explosion, transform.position, Quaternion.identity);
Destroy(this.gameObject);
}
if (health > 100)
{
health = maxHealth;
}
}
public void DestroyMe()
{
Destroy(this.gameObject);
}
}