37 lines
783 B
C#
37 lines
783 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class SoundMusic : MonoBehaviour
|
|
{
|
|
private static SoundMusic instance;
|
|
public static SoundMusic Instance => instance;
|
|
|
|
private AudioSource soundSource;
|
|
|
|
void Awake()
|
|
{
|
|
instance = this;
|
|
|
|
soundSource = this.GetComponent<AudioSource>();
|
|
|
|
//通过数据 来设置 音乐的大小和开关
|
|
MusicData data = GameDataMgr.Instance.musicData;
|
|
SetIsOpen(data.isOpen);
|
|
}
|
|
|
|
public void PlaySoundMusic()
|
|
{
|
|
if (GameDataMgr.Instance.musicData.isOpen)
|
|
{
|
|
soundSource.PlayOneShot(soundSource.clip);
|
|
}
|
|
}
|
|
|
|
//开关背景音乐的方法
|
|
public void SetIsOpen(bool isOpen)
|
|
{
|
|
soundSource.mute = !isOpen;
|
|
}
|
|
}
|