以下是我们要实现的一个简单的游戏菜单:
以下是实现这个菜单的代码:
using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.Audio; public class Menu : MonoBehaviour { public GameObject PauseMenu; public AudioMixer BGMAudioMixer; public AudioMixer SoundAudioMixer; public void PlayGame() { SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1); } public void QuitGame() { Application.Quit(); } public void PauseGame() { PauseMenu.SetActive(true); Time.timeScale = 0f; //这行是暂停游戏 } public void ReturnGame() { PauseMenu.SetActive(false); Time.timeScale = 1f; //1f是恢复原来的画面运动,0.5f可实现大升格感觉 } public void SetVolume(float value) { BGMAudioMixer.SetFloat("BgmVolume", value); } public void SoundVolume(float value) { SoundAudioMixer.SetFloat("SoundVolume", value); } }
从PauseGame开始,下面的代码就是这个简易菜单的代码
标签:UnityEngine,菜单,游戏,void,value,PauseMenu,制作,public From: https://www.cnblogs.com/qingyuan0213/p/17558622.html