Spelunx Cavern SDK
 
Loading...
Searching...
No Matches
GameManager.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using UnityEngine;
4using Spelunx.Vive;
5
6public class GameManager : MonoBehaviour
7{
8 public ZoneData[] zones;
10
11 [Serializable]
12 public class ZoneData
13 {
14 public bool isActive = false;
15 public bool touched = false;
16 public float volume = 0;
17 public AudioSource sound;
18 public Material onMaterial;
19 public Material offMaterial;
20 public MeshRenderer frog;
21 public Light light;
22 public Color onColor;
23
24 public IEnumerator FadeOutSound()
25 {
26 sound.volume = Mathf.MoveTowards(sound.volume, 0, Time.deltaTime);
27 volume = sound.volume;
28 if (sound.volume <= 0.001f)
29 {
30 sound.Stop();
31 }
32 yield return new WaitForEndOfFrame();
33 }
34 }
35
36 // Start is called once before the first execution of Update after the MonoBehaviour is created
37 void Start()
38 {
39 foreach (ZoneData z in zones)
40 {
41 z.sound.volume = 0;
42 }
43 }
44
45 // Update is called once per frame
46 void Update()
47 {
49 {
50 if (t.zone != -1)
51 {
52 zones[t.zone].isActive = true;
53 zones[t.zone].touched = true;
54 zones[t.zone].volume = Mathf.Max(zones[t.zone].volume, t.distance);
55 }
56 }
57
58 foreach (ZoneData z in zones)
59 {
60 if (!z.touched)
61 {
62 z.isActive = false;
63 StartCoroutine(z.FadeOutSound());
64 }
65 if (z.isActive)
66 {
67 StopCoroutine(z.FadeOutSound());
68 z.sound.volume = z.volume;
69 if (!z.sound.isPlaying)
70 {
71 z.sound.Play();
72 }
73 z.light.color = z.onColor;
74 z.frog.material = z.onMaterial;
75 }
76 else
77 {
78 // z.light.color = new Color(71, 71, 71);
79 z.light.color = Color.white;
80 z.frog.material = z.offMaterial;
81 }
82 z.touched = false;
83 }
84 }
85}
AudioSource sound
Definition: GameManager.cs:17
IEnumerator FadeOutSound()
Definition: GameManager.cs:24
MeshRenderer frog
Definition: GameManager.cs:20
ZoneData[] zones
Definition: GameManager.cs:8
Zones trackerZones
Definition: GameManager.cs:9
ZonedTracker[] zonedTrackers
Definition: Zones.cs:21