using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MusicPlayer : MonoBehaviour
{
private static MusicPlayer Instance = null;
void Start () {
if (Instance != null)
{
Destroy(gameObject);
}
else
{
Instance = this;//若不加此句则instance一直为空,DontDestroyOnLoad会反复创建他所在的gameobject,加上此句保证了MusicPlayer只能有一个实例
DontDestroyOnLoad(gameObject);
}
}
}