1. 程式人生 > >Unity中通過場景切換但音樂繼續播放

Unity中通過場景切換但音樂繼續播放

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");
            }
        }
    }
}