所以,我写的剧本并没有完全发挥作用。我有一个暂停按钮,当我按下它时,它会触发我的bool并显示它正常工作,但是当我暂停"暂停"我的用户界面没有弹出,我的游戏也没有停留在后台。我希望你能清楚地理解。我是初学者!
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class PauseManager : MonoBehaviour {
public GameObject pauseMenu;
public bool paused = false;
public void start()
{
pauseMenu.SetActive(false);
}
public void update()
{
if(Input.GetButtonDown("escape"))
{
paused = !paused;
}
if (paused)
{
pauseMenu.SetActive(true);
Time.timeScale = 0;
}
if (!paused)
{
pauseMenu.SetActive(false);
Time.timeScale = 1;
}
}
public void Resume()
{
paused = false;
}
public void pauseButton()
{
paused = true;
}
}
答案 0 :(得分:0)
建议您将代码更改为:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class PauseManager : MonoBehaviour {
public GameObject pauseMenu;
bool paused = false;
void Start()
{
pauseMenu.SetActive(false);
}
void Update()
{
if(Input.GetButtonDown("escape"))
{
paused = !paused;
}
if (paused)
{
PauseGame();
}
if (!paused)
{
ResumeGame();
}
}
void PauseGame(){
pauseMenu.SetActive(true);
Time.timeScale = 0f;
}
void ResumeGame(){
pauseMenu.SetActive(false);
Time.timeScale = 1f;
}
public void Resume()
{
ResumeGame();
}
public void pauseButton()
{
PauseGame();
}
}
我认为问题在于,当您按暂停按钮时,时间刻度为0,并且更新不起作用。