-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shooting.cs
125 lines (89 loc) · 3.56 KB
/
Shooting.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
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
118
119
120
121
122
123
124
125
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Shooting : MonoBehaviour {
public Text damageText;
public float damage;
public Text speedText;
public float speed;
public Text rangeText;
public float range;
public GameObject rangeZone;
public Text critChanceText;
public float critChance;
public Text critDamageText;
public float critDamage;
public Text doubleChanceText;
public float doubleChance;
public Text bounceChanceText;
public float bounceChance;
public Text multiChanceText;
public float multiChance;
public Text multiNumberText;
public float multiNumber;
public float shotSpeed;
public GameObject[] pellet;
private int pelletLength;
private int pelletIndex;
private bool canShoot = true;
private void Start() {
pelletLength = pellet.Length;
}
void Update() {
damage = float.Parse(damageText.text);
speed = float.Parse(speedText.text)/10;
range = float.Parse(rangeText.text)/10;
critChance = float.Parse(critChanceText.text)/100;
critDamage = float.Parse(critDamageText.text)/100 * damage + damage;
doubleChance = float.Parse(doubleChanceText.text); //1% chance each
bounceChance = float.Parse(bounceChanceText.text)/100;
multiChance = float.Parse(multiChanceText.text)/100;
multiNumber = float.Parse(multiNumberText.text);
if (canShoot && gameObject.GetComponent<LocateEnemy>().target != null && Random.Range(1, 100) <= doubleChance) {
StartCoroutine(DoubleShoot());
}
else if (canShoot && gameObject.GetComponent<LocateEnemy>().target != null) {
StartCoroutine(Shoot());
}
rangeZone.transform.localScale = new Vector2(range * 2, range*2);
}
private IEnumerator DoubleShoot() {
Appearance(pellet[pelletIndex]);
while (pellet[pelletIndex].activeInHierarchy == true) {
pelletIndex = Random.Range(0, pelletLength - 1);
}
canShoot = false;
yield return new WaitForSeconds(0.2f);
Appearance(pellet[pelletIndex]);
while (pellet[pelletIndex].activeInHierarchy == true) {
pelletIndex = Random.Range(0, pelletLength - 1);
}
yield return new WaitForSeconds(( 1 / speed ) - 0.2f);
canShoot = true;
}
private IEnumerator Shoot() {
Appearance(pellet[pelletIndex]);
while (pellet[pelletIndex].activeInHierarchy == true) {
pelletIndex = Random.Range(0, pelletLength-1);
}
canShoot = false;
yield return new WaitForSeconds(1 / speed);
canShoot = true;
}
public void Appearance(GameObject appeared) {
appeared.SetActive(true);
if (appeared.GetComponent<CircleCollider2D>() != null) {
appeared.GetComponent<CircleCollider2D>().enabled = true;
}
if (appeared.GetComponent<BoxCollider2D>() != null) {
appeared.GetComponent<BoxCollider2D>().enabled = true;
}
if (appeared.GetComponent<CapsuleCollider2D>() != null) {
appeared.GetComponent<CapsuleCollider2D>().enabled = true;
}
if (appeared.GetComponent<Rigidbody2D>() != null) {
appeared.GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Dynamic;
}
}
}