Skip to content
Snippets Groups Projects
Commit 08859e63 authored by David Huss's avatar David Huss :speech_balloon:
Browse files

Rename variables fix some behaviour

parent 4b75f688
No related branches found
No related tags found
No related merge requests found
using UnityEngine; using UnityEngine;
using UnityEngine.Events; using UnityEngine.Events;
using System.Collections; using System.Collections;
using System; using System;
[RequireComponent(typeof(AudioSource))]
[RequireComponent(typeof(Collider))]
public class SoundManager : MonoBehaviour public class SoundManager : MonoBehaviour
{ {
public Boolean stop_on_exit = false; public Boolean stopOnExit = false;
public Boolean pause_on_exit = false; public Boolean pauseOnExit = false;
public Boolean start_on_enter = true; public Boolean startOnEnter = true;
public Boolean start_after_awake = false; public Boolean startAfterAwake = false;
public Boolean play_only_once = false; public Boolean playOnlyOnce = false;
public float start_delay = 0.0f; public float startDelay = 0.0f;
public float stop_delay = 0.0f; public float stopDelay = 0.0f;
Boolean never_played_before = true; Boolean never_played_before = true;
AudioSource source; AudioSource source;
...@@ -19,40 +21,42 @@ public class SoundManager : MonoBehaviour ...@@ -19,40 +21,42 @@ public class SoundManager : MonoBehaviour
void Awake() void Awake()
{ {
source = GetComponent<AudioSource>(); source = GetComponent<AudioSource>();
if (start_after_awake) source.playOnAwake = false;
source.Stop();
if (startAfterAwake)
{ {
Invoke("Play", start_delay); Invoke("Play", startDelay);
} }
} }
void OnTriggerEnter(Collider other) void OnTriggerEnter(Collider other)
{ {
if (start_on_enter) if (startOnEnter)
{ {
// Start sound only if we want to "restart on enter" // Start sound only if we want to "restart on enter"
// Otherwise only start it, if it isn't playing already // Otherwise only start it, if it isn't playing already
if (never_played_before || !source.isPlaying) if (never_played_before || !source.isPlaying)
{ {
Invoke("Play", start_delay); Invoke("Play", startDelay);
} }
} }
} }
void OnTriggerExit(Collider other) void OnTriggerExit(Collider other)
{ {
if (stop_on_exit) if (stopOnExit)
{ {
Invoke("Stop", stop_delay); Invoke("Stop", stopDelay);
} }
else if (pause_on_exit) else if (pauseOnExit)
{ {
Invoke("Pause", stop_delay); Invoke("Pause", stopDelay);
} }
} }
void Play() void Play()
{ {
if (play_only_once) { if (playOnlyOnce) {
if (!Data.instance.PlayedSound(source.name)) { if (!Data.instance.PlayedSound(source.name)) {
source.Play(); source.Play();
never_played_before = false; never_played_before = false;
...@@ -61,6 +65,8 @@ public class SoundManager : MonoBehaviour ...@@ -61,6 +65,8 @@ public class SoundManager : MonoBehaviour
}else{ }else{
source.Play(); source.Play();
never_played_before = false; never_played_before = false;
Debug.LogFormat("Registered as Played: {0}", source.name);
Data.instance.RegisterSound(source.name);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment