1
Fork 0
mirror of https://github.com/Steffo99/gravity-fusion.git synced 2024-11-22 16:24:20 +00:00
gravity-fusion/Assets/Components/MusicManager.cs

54 lines
1.2 KiB
C#
Raw Normal View History

2019-10-05 13:59:17 +00:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2019-10-06 17:04:47 +00:00
public class MusicManager : MonoBehaviour
{
public AudioSource baseLayer;
public List<AudioSource> layers;
2019-10-05 13:59:17 +00:00
2019-10-06 17:04:47 +00:00
protected bool neverStarted;
2019-10-05 13:59:17 +00:00
2019-10-06 17:04:47 +00:00
protected void Start()
{
foreach(AudioSource audioSource in layers) {
audioSource.volume = 0;
2019-10-05 13:59:17 +00:00
}
2019-10-06 17:04:47 +00:00
neverStarted = true;
2019-10-05 13:59:17 +00:00
}
2019-10-06 17:04:47 +00:00
public void UpdateLayers(int maxTier) {
if(maxTier == -1) {
baseLayer.volume = 1f;
}
else {
baseLayer.volume = 0f;
}
2019-10-05 13:59:17 +00:00
2019-10-06 17:04:47 +00:00
if(neverStarted) {
foreach(AudioSource layer in layers) {
layer.Play();
}
neverStarted = false;
}
2019-10-05 13:59:17 +00:00
2019-10-06 17:04:47 +00:00
if(maxTier >= layers.Count) {
foreach(AudioSource layer in layers) {
layer.volume = 1f;
}
}
else {
for(int i = 0; i < layers.Count; i++) {
if(maxTier >= i) {
layers[i].volume = 1f;
}
else {
layers[i].volume = 0f;
}
}
2019-10-05 13:59:17 +00:00
}
}
}