Unity中通過場景切換但音樂繼續播放
阿新 • • 發佈:2019-02-15
public class
Test: MonoBehaviour
{
public GameObject objPrefabInstantSource;//音樂預知物體
private GameObject musicInstant = null;//場景中是否有這個物體
// Use this for initialization
void Start()
{
musicInstant = GameObject.FindGameObjectWithTag("sounds");
if (musicInstant == null)
{
musicInstant = (GameObject)Instantiate(objPrefabInstantSource);
}
}
void OnGUI()
{
if (GUILayout.Button("Load Level"))
{
if (Application.loadedLevelName == "001")//關於這個下面有詳細介紹
{
Application.LoadLevel("002");
}
else
{
Application.LoadLevel("001");
}
}
}
}
{
public GameObject objPrefabInstantSource;//音樂預知物體
private GameObject musicInstant = null;//場景中是否有這個物體
// Use this for initialization
void Start()
{
musicInstant = GameObject.FindGameObjectWithTag("sounds");
if (musicInstant == null)
{
musicInstant = (GameObject)Instantiate(objPrefabInstantSource);
}
}
void OnGUI()
{
if (GUILayout.Button("Load Level"))
{
if (Application.loadedLevelName == "001")//關於這個下面有詳細介紹
{
Application.LoadLevel("002");
}
else
{
Application.LoadLevel("001");
}
}
}
}