码迷,mamicode.com
首页 > 其他好文 > 详细

游戏暂停界面 和 音量开关 背景音乐 音效调节

时间:2015-07-28 18:36:13      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:教程



using UnityEngine;

using System.Collections;
using UnityEngine.UI;
using UnityEngine.Audio;
#if UNITY_EDITOR
using UnityEditor;
#endif


public class PauseManager : MonoBehaviour {

public AudioMixerSnapshot paused;
public AudioMixerSnapshot unpaused;

Canvas canvas;

void Start()
{
canvas = GetComponent<Canvas>();
}

void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
canvas.enabled = !canvas.enabled;
Pause();
}
}

public void Pause()
{
Time.timeScale = Time.timeScale == 0 ? 1 : 0;
Lowpass ();

}

void Lowpass()
{
if (Time.timeScale == 0)
{
paused.TransitionTo(.01f);
}

else

{
unpaused.TransitionTo(.01f);
}
}

public void Quit()
{
#if UNITY_EDITOR 
EditorApplication.isPlaying = false;
#else 
Application.Quit();
#endif
}

}

————————————————————————————————————————————————

using UnityEngine;
using System.Collections;
using UnityEngine.Audio;


public class MixLevels : MonoBehaviour {


public AudioMixer masterMixer;


public void SetSfxLvl(float sfxLvl)
{
masterMixer.SetFloat("sfxVol", sfxLvl);
}


public void SetMusicLvl (float musicLvl)
{
masterMixer.SetFloat ("musicVol", musicLvl);
}
}




版权声明:本文为博主原创文章,未经博主允许不得转载。

游戏暂停界面 和 音量开关 背景音乐 音效调节

标签:教程

原文地址:http://blog.csdn.net/haifeng619/article/details/47108287

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!