【发布时间】:2018-02-27 15:30:13
【问题描述】:
我有这段代码可以在所有场景中播放音频,它工作正常,暂停也工作。但是当我离开现场并返回时,音频将不再暂停。我应该怎么做才能暂停音频?
public AudioClip sound;
public AudioSource source
{
get
{
return GetComponent<AudioSource>();
}
}
void Start ()
{
gameObject.AddComponent<AudioSource>();
source.clip = sound;
if (source.playOnAwake == true)
source.Play ();
Button butn = GameObject.Find ("soundButton").GetComponent<Button>();
butn.onClick.AddListener(PlaySoud);
}
public void PlaySoud ()
{
if (source.isPlaying)
{
source.Pause();
}
else
{
source.Play ();
}
}
void Awake()
{
GameObject[] obj = GameObject.FindGameObjectsWithTag ("soundobject");
if(obj.Length > 1)
{
Destroy (this.gameObject);
}
DontDestroyOnLoad (this.gameObject);
}
【问题讨论】:
标签: unity3d