- Home /
Button Disappears?
I have a pause button but whenever I run my code it works fine the first time but then it disappears.
Here is code: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;
public class PauseControllerScript : MonoBehaviour {
public string mainMenu;
public bool isPaused;
public GameObject pauseMenuCanvas;
public GameObject spawner;
public GameObject cups;
public GameObject button;
// Use this for initialization
void Start () {
}
// Update is called once per frame
public void Update () {
if (isPaused) {
pauseMenuCanvas.SetActive (true);
Time.timeScale = 0f;
spawner.GetComponent <BallSpawn> ().enabled = false;
} else {
pauseMenuCanvas.SetActive (false);
Time.timeScale = 1f;
}
}
public void Resume () {
isPaused = false;
}
public void Quit () {
SceneManager.LoadScene ("StartScreen");
}
public void Yes () {
isPaused = true;
button.SetActive (false);
}
}
first tell me what you wants to do in your project? why you put condition in update? what you wants to do?
if you make pause system then
public void ClickPause() { pausecanvas.setavtive(true); } public void ClickResume() { pausecanvas.setavtive(false); }
thats it
just make sure where are updating your isPaused
because the bool turns to false and in your update you have check that if bool false then never active `pause$$anonymous$$enuCanvas. $$anonymous$$ake sure on pause button you changed the state whatever you desired. As @soniya_unity suggested good
public void ClickPause()
{
pausecanvas.setavtive(true);
}
public void ClickResume()
{
pausecanvas.setavtive(false);
}
Answer by Garazbolg · Jul 21, 2017 at 09:33 AM
Well because you're setting it to inactive in your Yes function and never setting it back to active.
You just need :
public void Resume () {
button.SetActive(true);
isPaused = false;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612130758im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to enable UI collision while timeScale is 0? 2 Answers
Make a button selectable for controller but not interactable 0 Answers
UI Buttons Stop Working After I Load Another Scene And Then Come Back. 4 Answers
Functions aren't appearing in the onClick editor..... 1 Answer
How to make UI buttons so my player can move along certain lines 0 Answers