-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMissile.cs
More file actions
57 lines (54 loc) · 1.81 KB
/
Missile.cs
File metadata and controls
57 lines (54 loc) · 1.81 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Missile : MonoBehaviour
{
[SerializeField]
private float _speed = 80f;
[SerializeField]
private GameObject _explosion;
// Update is called once per frame
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);
}
Destroy(this.gameObject, 20f);
}
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Laser")
{
Instantiate(_explosion, transform.position, Quaternion.identity);
Destroy(this.gameObject);
}
if (other.tag == "Asteroid" )
{
Instantiate(_explosion, transform.position, Quaternion.identity);
Instantiate(_explosion, other.transform.position, Quaternion.identity);
Destroy(other.gameObject);
Destroy(this.gameObject);
}
if(other.name == "Enemy_Weapon")
{
Instantiate(_explosion, transform.position, Quaternion.identity);
Instantiate(_explosion, other.transform.position, Quaternion.identity);
Destroy(other.transform.parent.gameObject);
Destroy(this.gameObject);
}
}
}