【发布时间】:2015-06-26 09:35:44
【问题描述】:
我正在尝试让一些音乐在我开始我的安卓游戏时淡出。音乐在主菜单中播放,然后在播放器单击播放时淡出。我可以让音乐停止,但不会淡出。
我正在尝试使用这个来淡出:
using UnityEngine;
using System.Collections;
public class MusicScript : MonoBehaviour
{
static MusicScript instance;
bool doneFading;
void Start()
{
if(instance == null)
{
instance = this;
DontDestroyOnLoad(gameObject);
}
else if (instance != this)
{
Destroy(gameObject);
}
}
void Update()
{
if (Application.loadedLevelName == "Flappy Drone Gameplay Screen")
{
FadeMusic();
if (doneFading == true)
{
Destroy(gameObject);
}
}
}
IEnumerator FadeMusic()
{
for (int i = 9; i > 0; i--)
{
Debug.Log("here");
instance.audio.volume = i * 0.1f;
yield return new WaitForSeconds(0.5f);
Debug.Log("lowered volume");
}
doneFading = true;
}
}
感谢任何帮助!
【问题讨论】:
标签: android audio unity3d fade