- Home /
destroy gui after game paused
Destroy GUI after Paused Game Posted: 03:21 PM 1 Hour Ago Hello,
here is the escript to pause with the GUI:
var pauseUI: Transform;
function Update ()
{
if (Input.GetKey (KeyCode.Menu)) {
pause ();
}
}
function pause () {
Time.timeScale = 0;
Instantiate (pauseUI);
}
How Do I Destroy the GUI after I put the Time.timeScale = 1; ? thanks for the help
Answer by Justin Warner · May 14, 2012 at 11:51 PM
Psuedo code: isPaused = false;
function awake()
{
isPaused = false;
}
function update()
{
//If pause is hit, make isPaused=true;
//If pause is hit again, or unpause, w/e, make isPaused = false;
}
function update()
{
//If (isPaused)
//Draw pause menu.
//else
//Draw game graphics.
}
Rough and unformatted, but works.
I guess your second update should be OnGUI? ;)
Even when it's pseudo code, why is Awake and Update lowercase?
Answer by Bunny83 · May 15, 2012 at 12:24 AM
var pauseUI : Transform;
private var pauseInstance : Transform;
function pause () {
Time.timeScale = 0.0;
pauseInstance = Instantiate (pauseUI) as Transform;
}
function unPause () {
Time.timeScale = 1.0;
if (pauseInstance != null)
Destroy(pauseInstance.gameObject);
}
did you drag and drop your GUI gameObject into the Inspector for this script's gameObject?
do you need to destroy the GUI, or just hide it?
private var isPaused : boolean = false;
function Update()
{
if (Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.P))
{
if (isPaused)
{
isPaused = false;
Time.timeScale = 1.0;
}
else
{
isPaused = true;
Time.timeScale = 0.0;
}
}
}
function OnGUI()
{
if (isPaused)
{
GUI.Box(Rect(10, 10, 200, 25), "is PAUSED");
Debug.Log("Hello World");
}
}
Answer by mdinizzz · May 15, 2012 at 04:06 AM
I found the solution simply Search for the UI then destroy it. It would be best if you give the tag That UI ("UI")
Destroy (GameObject.FindWithTag ("UI")),
:)
That's the most inefficient way. If something else is tagged "UI" (maybe by accident) it won't do what you expect.
Can you tell me what exactly "did not work" mean? Any errors? What happens?
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
GUI Appear Help 1 Answer
Setting Scroll View Width GUILayout 1 Answer