Unity 背景音乐 跨场景播放
来源:互联网 发布:重新加载数据会丢吗 编辑:程序博客网 时间:2024/05/22 13:42
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 () {
}
}
2、建Text.cs,加到每个场景任意物体上。
using UnityEngine;using System.Collections;
public class Test : MonoBehaviour {
public GameObject bgmPrefab;
public GameObject bgmInstance = null;
// Use this for initialization
void Start () {
bgmInstance= GameObject.FindGameObjectWithTag("sound");
if (bgmInstance == null)
{
bgmInstance = (GameObject)Instantiate(bgmPrefab);
}
}
// Update is called once per frame
void Update () {
}
}
3、把第1步建立的空物体去掉,以免出现声音重叠。
阅读全文
0 0
- Unity 背景音乐 跨场景播放
- Unity播放背景音乐
- 场景切换时背景音乐不间断播放
- untiy3d 场景切换时背景音乐不间断播放
- Unity3d 场景切换时背景音乐不间断播放
- 播放背景音乐
- 背景音乐播放
- 背景音乐播放
- 背景音乐播放
- 背景音乐播放
- 【Cocos2d-x 3.x】 场景切换生命周期、背景音乐播放和场景切换原理与源码分析
- Vuforia+Unity AR场景播放音频控制
- delphi播放mp3背景音乐
- Inno Setup 播放背景音乐
- 博客背景音乐播放器
- C#播放背景音乐
- jsp播放背景音乐
- windows form播放背景音乐
- 实验项目二:栈的基本操作及其应用
- GitHub使用之12个实用技巧,你get了几个?
- Error:(2, 0) Plugin with id 'com.github.dcendents.android-maven' not found. <a href="openFile:D:\Git
- 结构体所占内存
- “逐渐失效”的摩尔定律
- Unity 背景音乐 跨场景播放
- ViewPager实现画廊
- C++——临时对象
- 用Hive分析函数lead计算用户页面的停留时长
- smashthestack的wp
- a到b之间的整数求和
- LINK : fatal error LNK1104: 无法打开文件“opencv_calib3d249d.lib”问题解决
- 万树IT:Net程序员该怎样成为大牛?
- Unity格子类三消游戏【物体下落】小细节(Unity萌新的备忘录)