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 System.Collections;
using System;
[RequireComponent(typeof(AudioSource))]
[RequireComponent(typeof(Collider))]
public class SoundManager : MonoBehaviour
{
public Boolean stop_on_exit = false;
public Boolean pause_on_exit = false;
public Boolean start_on_enter = true;
public Boolean start_after_awake = false;
public Boolean play_only_once = false;
public float start_delay = 0.0f;
public float stop_delay = 0.0f;
public Boolean stopOnExit = false;
public Boolean pauseOnExit = false;
public Boolean startOnEnter = true;
public Boolean startAfterAwake = false;
public Boolean playOnlyOnce = false;
public float startDelay = 0.0f;
public float stopDelay = 0.0f;
Boolean never_played_before = true;
AudioSource source;
......@@ -19,40 +21,42 @@ public class SoundManager : MonoBehaviour
void Awake()
{
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)
{
if (start_on_enter)
if (startOnEnter)
{
// Start sound only if we want to "restart on enter"
// Otherwise only start it, if it isn't playing already
if (never_played_before || !source.isPlaying)
{
Invoke("Play", start_delay);
Invoke("Play", startDelay);
}
}
}
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()
{
if (play_only_once) {
if (playOnlyOnce) {
if (!Data.instance.PlayedSound(source.name)) {
source.Play();
never_played_before = false;
......@@ -61,6 +65,8 @@ public class SoundManager : MonoBehaviour
}else{
source.Play();
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