java如何连续播放多首音乐_在Unity3d中的多个场景之间交换时播放连续音乐

我有以下场景

包含带有音频源组件的游戏对象的主菜单场景

一个关于我们的场景

gameObject脚本:

using UnityEngine;

using System.Collections;

public class ManageMusic : MonoBehaviour

{

private static ManageMusic _instance;

public static ManageMusic instance

{

get

{

if (_instance == null)

{

_instance = GameObject.FindObjectOfType();

//Tell unity not to destroy this object when loading a new cene!

DontDestroyOnLoad(_instance.gameObject);

}

return _instance;

}

}

private void Awake()

{

if (_instance == null)

{

Debug.Log("Null");

//If I am the first instance, make me the Singleton

_instance = this;

DontDestroyOnLoad(this);

}

else

{

//If a Singleton already exists and you find

//another reference in scene, destroy it!

if (this != _instance)

{

Play();

Debug.Log("IsnotNull");

Destroy(this.gameObject);

}

}

}

public void Update()

{

if (this != _instance)

{

_instance = null;

}

}

public void Play()

{

this.gameObject.audio.Play();

}

}

关于我们返回按钮脚本:

using UnityEngine;

using System.Collections;

public class Back_btn : MonoBehaviour

{

void OnMouseDown()

{

Application.LoadLevel("MainMenu");

}

}

d9c00a1b-65a7-4046-8da3-f474325cc7c4.png

937c1c8d-ea65-42a0-9d0a-8d14202d67c8.png

当我点击aboutUs按钮时, Game Music object 继续播放,我可以听到音乐,但是当我返回主菜单时,仍然没有播放音乐 . 当我回到主菜单并且音频监听器将音量值设置为 1 时,我可以看到游戏对象没有被破坏,但我无法弄清楚问题是否有人可以帮助我

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值