[英]Unable to resume unity3D after pause
I am rather new to c#.我对 c# 比较陌生。 I am currently making a pause and resume screen.我目前正在暂停和恢复屏幕。 Pausing seems to work just fine, but the resuming functionality isn't.暂停似乎工作得很好,但恢复功能不是。
I used Debug.Log
to narrow the problem down to the chunk of code below.我使用Debug.Log
将问题缩小到下面的代码块。 When I hit the resume button after pausing, Paused
get set to false
, but nothing more happens, it's like if the code never reached the else
clause.当我在暂停后点击恢复按钮时, Paused
被设置为false
,但没有更多的事情发生,就像代码从未到达else
子句一样。
However, it does work, as before I hit pause, I get "resume" from Debug.Log
, but whenever I hit pause, I never get that.但是,它确实有效,就像在我点击暂停之前一样,我从Debug.Log
获得“恢复”,但是每当我点击暂停时,我都不会得到那个。
public static bool Paused;
public void ClickPauseButton()
{
Paused = true;
Time.timeScale = 0;
}
public void ClickResumeButton()//works
{
Paused = false;
Time.timeScale = 1;
}
void Update()
{
if(Paused == true)
{
showPaused();
HideUI();
}
else //This is the problem... Not a single resume
{
ShowUI();
hidePaused();
Debug.Log("resume");
}
}
You can change your script with my script which I have given below.您可以使用我在下面给出的脚本更改您的脚本。
using System.Collections.Generic;
using UnityEngine;
public class PausedMenu : MonoBehaviour
{
public static bool Paused = false;
public GameObject pauseUI;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (Paused)
{
ClickResumeButton();
}
else
{
ClickPauseButton();
}
}
}
public void ClickResumeButton()
{
pauseUI.SetActive(false);
Time.timeScale = 1f;
Paused = false;
}
public void ClickPauseButton()
{
pauseUI.SetActive(true);
Time.timeScale = 0f;
Paused = true;
}
}
using this you can easily manage your pauseUI.使用它您可以轻松管理您的 pauseUI。
Note : Attach your script to the parent game object.注意:将您的脚本附加到父游戏对象。 Make sure your game object is in this sequence.确保您的游戏对象按此顺序排列。 PauseCanvas -> PauseUI -> ResumeButton. PauseCanvas -> PauseUI -> ResumeButton。 you have to give this script to PauseCanvas.你必须把这个脚本交给 PauseCanvas。 And your pause button is outside of pauseUI.你的暂停按钮在 pauseUI 之外。
You can use this sequence which I have given below.您可以使用我在下面给出的这个序列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.