-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExplosionController.cs
More file actions
54 lines (53 loc) · 1.75 KB
/
ExplosionController.cs
File metadata and controls
54 lines (53 loc) · 1.75 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ExplosionController : MonoBehaviour
{
public AudioClip TorpedoHitSFX1, TorpedoHitSFX2;
public AudioClip SmallShipHitSFX1, SmallShipHitSFX2;
public Interactor interactor;
// Start is called before the first frame update
void Start()
{
interactor = GameObject.Find("ScreenCanvas").GetComponent<Interactor>();
}
public float timer = 0;
public void Explode(float time, string type) {
timer = time;
float random_chance = UnityEngine.Random.Range(0f, 1);
if (!GetComponent<AudioSource>().isPlaying) {
switch (type) {
case "Torpedo":
if (random_chance > 0.5f)
{
GetComponent<AudioSource>().clip = TorpedoHitSFX1;
}
else
{
GetComponent<AudioSource>().clip = TorpedoHitSFX2;
}
break;
case "Small Ship":
if (random_chance < 0.05f)
{
GetComponent<AudioSource>().clip = SmallShipHitSFX1;
}
else if (random_chance < 0.1f)
{
GetComponent<AudioSource>().clip = SmallShipHitSFX2;
}
break;
}
GetComponent<AudioSource>().volume = interactor.GetVolume() / 8;
GetComponent<AudioSource>().Play();
}
}
void FixedUpdate()
{
if (timer > 0) {
timer -= Time.deltaTime;
} else {
this.gameObject.SetActive(false);
}
}
}