【发布时间】:2019-03-23 22:42:08
【问题描述】:
我现在正在制作游戏,快完成了。现在我正在尝试通过按钮或切换按钮来控制音频的开启和关闭。
问题是,我将音频源游戏对象放在第一个场景中的启动画面中。我将音频或音乐按钮放在第三场景内的设置场景中。我已经制作了 c# 脚本来控制音频,但是当我尝试插入 AudioSource 时,它不能,因为它来自不同的场景。我试图将 AudioSource 放在同一个场景中,但音频没有开始,除非我先进入设置场景。
这是脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Music : MonoBehaviour
{
static Music instance = null;
public AudioSource Backsound;
private void Awake()
{
if (instance != null)
{
Destroy(gameObject);
}
else
{
instance = this;
GameObject.DontDestroyOnLoad(gameObject);
}
}
public void backsoundOnOff()
{
AudioSource bgsound = Backsound.GetComponent<AudioSource>();
if (bgsound.mute = true){
bgsound.mute = false;
}
else {
bgsound.mute = true;
}
}
}
【问题讨论】:
-
查看混音器。