1、把添加了AudioSource(声音片段:背景音乐)和“Dont DestroyOnLoad”脚本的空物体,拖成预设体。(注意预设体tag要设成“sound”,第2步脚本里要用。)----可以给空物体取一个有意义的名字,如bgmPrefab。
using UnityEngine;
using System.Collections;
public class DontDestroyMybgm : MonoBehaviour {
void Awake()
{
}
// Use this for initialization
void Start () {
DontDestroyOnLoad(this.gameObject);
}
// Update is called once per frame
void Update () {