- Home /
Creating a window within a window GUI
Title doesn't make very much sense,so allow me to explain.
I am trying to create a new button when this one is pressed. I did something similar in the main menu level for an options script. It is not working here though.
#pragma strict
//var startButton : Texture;
var numLives : GUIText;
var numIneternets : GUIText;
var pauseMenu = false;
var menuBox : Texture;
var quit : Texture;
var pauseButtonReturn : Texture;
var pauseButton : Texture;
var playButton : Texture;
var isPaused : boolean = true;
numLives.text = "Lives: " + ply.currentPlayerLives.ToString();
numIneternets.text = "Internets: " + ply.internets.ToString();
function menuAppear() {
GUI.Box (Rect (Screen.width / 2 + 15, Screen.height / 2 - 100, 200, 200), menuBox, "");
if (GUI.Button(Rect(Screen.width / 2 + 22, Screen.height / 2 - 91, 120, 120), quit, "")) {
Application.Quit();
}
}
function OnGUI() {
if (GUI.Button (Rect (Screen.width / 350, (Screen.height / 2) + 240, 50, 50), pauseButton, "")) {
if (isPaused != true) {
pauseMenu = false;
Time.timeScale = 0.0;
isPaused = true;
audio.Pause();
pauseButton = playButton;
} else {
pauseMenu = true;
Time.timeScale = 1.0;
isPaused = false;
audio.Play();
pauseButton = pauseButtonReturn;
}
if (pauseMenu){
menuAppear();
}
}
}
Comment
Best Answer
Answer by zharik86 · Sep 07, 2014 at 06:37 PM
Your script working. Only the button after clicking appears on one frame. That to correct it, transfer a condition for show button:
function OnGUI() {
if (GUI.Button (Rect (Screen.width / 350, (Screen.height / 2) + 240, 50, 50), pauseButton, "")) {
if (isPaused != true) {
pauseMenu = false;
Time.timeScale = 0.0;
isPaused = true;
audio.Pause();
pauseButton = playButton;
} else {
pauseMenu = true;
Time.timeScale = 1.0;
isPaused = false;
audio.Play();
pauseButton = pauseButtonReturn;
}
}
if (pauseMenu) { //Chane of a place of condition
menuAppear();
}
}
I hope that it will help you.
Your answer
![](https://koobas.hobune.stream/wayback/20220613162523im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Creating 2D art in a 3D world 3 Answers
A node in a childnode? 1 Answer
Simple heart system using new UI features? 0 Answers
Unlocking & "Equipping" Colors onto Sprites with c# 2 Answers
Unity2D - Box Collider 2D problem 0 Answers