You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.3 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Level1
{
public class AudioManager : MonoBehaviour
{
AudioSource bgmSource;
AudioSource effect;
public AudioClip bgm;
public AudioClip error;
public AudioClip end;
public AudioClip pb;
private void Awake()
{
bgmSource = gameObject.AddComponent<AudioSource>();
bgmSource.playOnAwake = false;
bgmSource.loop = true;
bgmSource.volume = 0.5f;
effect = gameObject.AddComponent<AudioSource>();
effect.playOnAwake = false;
effect.loop = false;
GameManager.StartGame += PlayPB;
GameManager.StartGame += PlayBGM;
}
private void OnEnable()
{
bgmSource.clip = bgm;
}
void PlayBGM() {
bgmSource.loop = true;
bgmSource.Play();
}
public void PlayErrorEffect() {
effect.clip = error;
effect.Play();
}
public void PlayEnd() {
effect.clip = end;
effect.Play();
}
public void PlayPB() {
effect.clip = pb;
effect.Play();
}
}
}