Unity3d 场景切换时背景音乐不间断播放

using UnityEngine;
using System.Collections;

public class ddd : MonoBehaviour {
    static ddd _instance;
    // Use this for initialization
    void Start () {
	
	}
    public static ddd instance    {
        get
        {
            if (_instance == null)
            {
                _instance = FindObjectOfType();
                DontDestroyOnLoad(_instance.gameObject);
            }
            return _instance;
        }
    }

    void Awake()
    {

        //此脚本永不消毁,并且每次进入初始场景时进行判断,若存在重复的则销毁
        if (_instance == null)
        {
            _instance = this;
            DontDestroyOnLoad(this);
        }
        else if (this != _instance)
        {
            Destroy(gameObject);
        }

    }
    // Update is called once per frame
    void Update () {
	
	}
}
Unity3d 场景切换时背景音乐不间断播放_第1张图片

你可能感兴趣的:(经典案例)