-
Notifications
You must be signed in to change notification settings - Fork 0
/
LaserScript.cs
146 lines (141 loc) · 4.85 KB
/
LaserScript.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using UnityEngine;
using System.Collections;
public class LaserScript : MonoBehaviour
{
private GameObject laser, laserStartCast, laser2, laserStartCast2, camPos;
private BoxCollider2D eye = null;
public Camera Camera;
public float shake = 0f;
public float shakeAmount = 0.7f;
public float decrease = 1f;
Vector3 camOrigPos = Vector3.zero;
public AudioClip bosslaser;
public bool boss2 = false;
void Start()
{
camPos = GameObject.Find("Cameraposition");
laser = GameObject.Find("Laser");
laser.SetActive(false);
if (boss2)
{
eye = gameObject.GetComponent<BoxCollider2D>();
eye.enabled = false;
laser2 = null;
laserStartCast2 = null;
laserStartCast = null;
}
else
{
laserStartCast = GameObject.Find("LaserStartCast");
laser2 = GameObject.Find("Laser2");
laserStartCast2 = GameObject.Find("LaserStartCast2");
laserStartCast.SetActive(false);
laser2.SetActive(false);
laserStartCast2.SetActive(false);
}
if (boss2)
{
StartCoroutine("timer2");
}
else
{
StartCoroutine("timer");
}
}
void Update()
{
camOrigPos = camPos.transform.position;
if (shake > 0f)
{
Vector2 rndShake = Random.insideUnitCircle * shakeAmount;
Camera.transform.localPosition = new Vector3(rndShake.x, rndShake.y - 0.3f, camOrigPos.z);
shake -= Time.deltaTime * decrease;
if(shake <= 0.1)
{
shake += 0.1f;
}
}
else
{
shake = 0.0f;
Camera.transform.position = camOrigPos;
}
}
IEnumerator timer()
{
yield return new WaitForSeconds(3f);
while (true)
{
float rng = Random.Range(0.5f, 2f);
laserStartCast.SetActive(true);
GetComponent<AudioSource>().PlayOneShot(bosslaser);
yield return new WaitForSeconds(0.9f);
laser.SetActive(true);
shake = 0.5f;
yield return new WaitForSeconds(rng);
shake = 0.0f;
laser.SetActive(false);
laserStartCast.SetActive(false);
yield return new WaitForSeconds(0.7f);
rng = Random.Range(0.5f, 2f);
laserStartCast2.SetActive(true);
GetComponent<AudioSource>().PlayOneShot(bosslaser);
yield return new WaitForSeconds(0.9f);
laser2.SetActive(true);
shake = 0.5f;
yield return new WaitForSeconds(rng);
shake = 0.0f;
laser2.SetActive(false);
laserStartCast2.SetActive(false);
yield return new WaitForSeconds(0.7f);
rng = Random.Range(0.5f, 2f);
laserStartCast.SetActive(true);
laserStartCast2.SetActive(true);
GetComponent<AudioSource>().PlayOneShot(bosslaser);
yield return new WaitForSeconds(0.9f);
laser.SetActive(true);
laser2.SetActive(true);
shake = 0.5f;
yield return new WaitForSeconds(rng);
shake = 0.0f;
laser.SetActive(false);
laser2.SetActive(false);
laserStartCast.SetActive(false);
laserStartCast2.SetActive(false);
yield return new WaitForSeconds(0.7f);
}
}
IEnumerator timer2()
{
Animator anim = laser.GetComponent<Animator>();
Animator bAnim = gameObject.GetComponent<Animator>();
BoxCollider2D box = laser.GetComponent<BoxCollider2D>();
box.enabled = false;
yield return new WaitForSeconds(0.3f);
eye.enabled = true;
yield return new WaitForSeconds(3f);
while (true)
{
bAnim.SetInteger("animState", 1);
yield return new WaitForSeconds(0.3f);
float rng = Random.Range(1.2f, 2f);
laser.SetActive(true);
anim.SetBool("laserStart", true);
GetComponent<AudioSource>().PlayOneShot(bosslaser);
yield return new WaitForSeconds(0.9f);
anim.SetBool("laserStart", false);
box.enabled = true;
eye.enabled = true;
shake = 0.5f;
yield return new WaitForSeconds(rng);
bAnim.SetInteger("animState", 2);
yield return new WaitForSeconds(0.2f);
shake = 0.0f;
laser.SetActive(false);
box.enabled = false;
yield return new WaitForSeconds(0.5f);
eye.enabled = true;
yield return new WaitForSeconds(3f);
}
}
}