1
0
Fork 0
Bildschirmflausch-LD41/Assets/Scripts/AudioControl.cs

82 lines
1.7 KiB
C#
Raw Normal View History

2018-04-23 00:29:44 +02:00

using UnityEngine;
using System.Collections;
using UnityEngine.Audio;
public class AudioControl : MonoBehaviour
{
public AudioMixer mixer;
2018-04-23 02:37:57 +02:00
public AudioSource maintheme;
2018-04-23 00:29:44 +02:00
public AudioSource gameovers;
public AudioSource[] soundeffects;
2018-04-23 02:37:57 +02:00
public enum Sfx { shoot, explosion, mobattack };
2018-04-23 00:29:44 +02:00
2018-04-23 02:37:57 +02:00
private const float lvlbgm = 37.879f;
private bool menu;
2018-04-23 00:29:44 +02:00
// Use this for initialization
void Start()
{
2018-04-23 02:37:57 +02:00
maintheme.loop = true;
gameovers.loop = true;
maintheme.Play();
}
private void Update()
{
if (maintheme.time >= 99.0f)
maintheme.time = lvlbgm;
if (gameovers.time >= 22.85f)
gameovers.time = 3;
}
public void GameOverBgm()
{
maintheme.Stop();
gameovers.Play();
}
public void MenuBgm()
{
if (gameovers.isPlaying)
gameovers.Stop();
maintheme.Play();
}
public void LevelBgm()
{
maintheme.time = lvlbgm;
2018-04-23 00:29:44 +02:00
}
public void SfxPlay(int sound)
{
soundeffects[sound].Play();
}
public void SfxStop(int sound)
{
soundeffects[sound].Stop();
}
public bool SfxPlaying(int sound)
{
return soundeffects[sound].isPlaying;
}
public void SetMasterVolume(float nvol)
{
mixer.SetFloat("masterVolume", Mathf.Clamp(nvol, -80f, 20f));
}
2018-04-23 02:37:57 +02:00
public void SetBgmVolume(float nvol)
{
mixer.SetFloat("bgmVolume", Mathf.Clamp(nvol, -80f, 20f));
}
public void SetSfxVolume(float nvol)
{
mixer.SetFloat("sfxVolume", Mathf.Clamp(nvol, -80f, 20f));
}
2018-04-23 00:29:44 +02:00
}
2018-04-23 02:37:57 +02:00