赞
踩
上一篇文章:
CSDNhttps://mp.csdn.net/mp_blog/creation/editor/122917227
内容如下
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class PauseMenu : MonoBehaviour
{
public static bool isPause = false;
public GameObject pauseMenuUI;
public GameObject settingMenuUI;
public Image settingImage;
private Color originColor;
void Start()
{
originColor = settingImage.color;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (isPause)
{
Resume();
}
else
{
Pause();
}
}
}
public void Resume()
{
pauseMenuUI.SetActive(false);
Time.timeScale = 1.0f;
isPause = false;
}
public void MainMenu()
{
isPause = false;
Time.timeScale = 1.0f;
SceneManager.LoadScene("MainMenu");
}
public void Pause()
{
pauseMenuUI.SetActive(true);
Time.timeScale = 0.0f;
isPause = true;
}
public void Setting()
{
if (isPause)
{
pauseMenuUI.SetActive(false);
settingMenuUI.SetActive(true);
isPause = false;
Time.timeScale = 0.0f;
settingImage.enabled = true;
}
}
}
Time.timeScale是用于暂停或开始游戏时间,isPause用于判断游戏是否暂停
然后依次添加点击事件,看过我上一篇文章的应该都懂。
然后我们要在开始先把PauseMenu调成false非激活状态。
因为我还不会做Setting,所以我做了个提示告诉大伙我还不会做。
以下是游戏效果
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。