【发布时间】:2017-03-09 20:41:25
【问题描述】:
我正在 Unity3d 中创建一个小游戏。这场比赛有4个场景。我创建了小型声音服务来播放/静音/取消静音我的游戏中的声音和音乐。我的大部分声音是通过游戏中的一些方法播放的,只有一个声音是通过点击按钮播放的。
这是我的声音服务:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SoundService : MonoBehaviour
{
public AudioSource efxSource;
public AudioSource musicSource;
public static SoundService instance = null;
public AudioClip dieSound;
public AudioClip pointSound;
public AudioClip newRecordSound;
public AudioClip flapSound;
public void MuteSounds()
{
if (efxSource.mute)
efxSource.mute = false;
else
efxSource.mute = true;
}
public void MuteMusic()
{
if (musicSource.mute)
musicSource.mute = false;
else
musicSource.mute = true;
}
void Awake()
{
if (instance == null)
instance = this;
else if(instance != this)
Destroy(gameObject);
DontDestroyOnLoad(gameObject);
}
public void PlaySingle(AudioClip clip)
{
efxSource.clip = clip;
efxSource.Play();
}
public void PlayLoseSound()
{
efxSource.clip = dieSound;
efxSource.Play();
}
public void PlayPointSound()
{
efxSource.clip = pointSound;
efxSource.Play();
}
public void PlayFlapSound()
{
efxSource.clip = flapSound;
efxSource.Play();
}
public void PlayNewRecordSound()
{
efxSource.clip = newRecordSound;
efxSource.Play();
}
}
问题是:当我在场景之间移动时,efxSource.mute 和 musicSource.mute 总是切换为 false。
我想在主菜单静音,然后开始新游戏时,音乐仍然静音。
【问题讨论】:
标签: c# visual-studio audio unity3d