- Home /
My buttons do not appear when paused?
I am trying to make my own puse script from various tutorials and snippets, it was going ok till i started to add buttons.. At first they would appear even when not paused. not they don't appear at all.
Maybe i am not putting it in the right place? i tried the ONGUI but it kept saying error.
//My First (Pause Menu) Script 4 July, 2013
// I'm sure it is full of errors lol, but it's a start!
// Im using what i am reading in tutorials, plus some code examples..
var paused : boolean = false;
var pausedGUI : GUITexture;
var gameName : String = "Game Paused";
var skin:GUISkin;
var pauseTexture : Texture2D;
var windowRect0 : Rect = Rect (670, 250, 150, 50);
var windowRect1 : Rect = Rect (670, 300, 120, 50);
var windowRect2 : Rect = Rect (670, 350, 120, 50);
var windowRect3 : Rect = Rect (670, 400, 120, 50);
static var backgroundColor : Color;
function Update () {
if(Input.GetKeyDown("p") && paused == false)
{
//IF GAME IS PAUSED
paused = true;
Time.timeScale = 0;
AudioListener.pause = true;
Screen.showCursor = true;
GUI.backgroundColor = Color.blue;
guiTexture.texture = pauseTexture;
//GUISkin.CreateInstance new.skin;
} else if(Input.GetKeyDown("p") && paused == true) {
//IF GAME IS NOT PAUSED
paused = false;
AudioListener.pause = false;
Time.timeScale = 1.0;
Screen.showCursor = false;
}
}
function OnGUI () {
//Make New Windows
if(Input.GetKeyDown("p") && paused == true) {
guiTexture.texture = pauseTexture;
guiText.text = gameName;
GUI.color = Color.green;
windowRect0 = GUI.Window (0, windowRect0, PauseWindow, "Resume Game");
GUI.color = Color.yellow;
windowRect1 = GUI.Window (1, windowRect1, PauseWindow, "Load, Save Game");
GUI.color = Color.yellow;
windowRect2 = GUI.Window (2, windowRect2, PauseWindow, "Load, Save Game");
GUI.color = Color.yellow;
windowRect3 = GUI.Window (3, windowRect3, PauseWindow, "Load, Save Game");
}
}
// Make the contents of the window.
// The value of GUI.color is set to what it was when the window
// was created in the code above.
function PauseWindow (windowID : int) {
if (GUI.Button (Rect (10,20,100,20), "Hello World"))
print ("Got a click in window with color " + GUI.color);
// Make the windows be draggable.
GUI.DragWindow (Rect (0,0,10000,10000));
}
Im trying to get it to appear as: Game Paused Button 1 Button 2 Button 3 Button 4 with a gray background image
Answer by oliver-jones · Jul 04, 2013 at 09:33 PM
Here try this dude:
var paused : boolean = false;
var pausedGUI : GUITexture;
var gameName : String = "Game Paused";
var skin:GUISkin;
var pauseTexture : Texture2D;
var windowRect0 : Rect = Rect (670, 250, 150, 50);
var windowRect1 : Rect = Rect (670, 300, 120, 50);
var windowRect2 : Rect = Rect (670, 350, 120, 50);
var windowRect3 : Rect = Rect (670, 400, 120, 50);
static var backgroundColor : Color;
function Update () {
if(Input.GetKeyDown("p") && paused == false){
//IF GAME IS PAUSED
Time.timeScale = 0;
AudioListener.pause = true;
Screen.showCursor = true;
GUI.backgroundColor = Color.blue;
guiTexture.texture = pauseTexture;
//GUISkin.CreateInstance new.skin;
paused = true;
}
else if(Input.GetKeyDown("p") && paused == true) {
//IF GAME IS NOT PAUSED
AudioListener.pause = false;
Time.timeScale = 1.0;
Screen.showCursor = false;
paused = false;
}
}
function OnGUI () {
//Make New Windows
if(paused == true) {
guiTexture.texture = pauseTexture;
guiText.text = gameName;
GUI.color = Color.green;
windowRect0 = GUI.Window (0, windowRect0, PauseWindow, "Resume Game");
GUI.color = Color.yellow;
windowRect1 = GUI.Window (1, windowRect1, PauseWindow, "Load, Save Game");
GUI.color = Color.yellow;
windowRect2 = GUI.Window (2, windowRect2, PauseWindow, "Load, Save Game");
GUI.color = Color.yellow;
windowRect3 = GUI.Window (3, windowRect3, PauseWindow, "Load, Save Game");
}
}
// Make the contents of the window.
// The value of GUI.color is set to what it was when the window
// was created in the code above.
function PauseWindow (windowID : int) {
if (GUI.Button (Rect (10,20,100,20), "Hello World"))
print ("Got a click in window with color " + GUI.color);
// Make the windows be draggable.
GUI.DragWindow (Rect (0,0,10000,10000));
}
Let me know what happens (I'm not hugely familiar with GUI windows my self, to be honest)
Nope, still nothing appears on the screen, but the game does pause. well it still scrolls up down (mouse) for some damn reason make3s it hard to select stuff...
Bump. Any help would be great! If i move the buttons below the if paused they show up. and no error on GUI, so how can i do this.
yes i did, sorry i did not reply. i choose a texture to use yes.
Answer by Crazsta · Jul 05, 2013 at 07:57 AM
Well I know that this isn't exactly what you are trying to make but it should help you see if there is something wrong with your early script as this is the prototype pause I am using in a game I am currently developing. #pragma strict
var pressed1 : boolean = false;
var pressed2 : boolean = false;
public static var paused : boolean = false;
var sX : int;
var sY : int;
function Start(){
sX = Screen.currentResolution.width;
sY = Screen.currentResolution.height;
}
function Update () {
if(Interaction.talking == false){
if(Input.GetKeyDown(KeyCode.Escape) && pressed1 == false && pressed2 == false){
pressed1 = true;
paused = true;
}
if(pressed2 == true && pressed1 == true){
pressed1 = false;
pressed2 = false;
paused = false;
}
}
}
function OnGUI(){
if(pressed1 == true){
if(GUI.Button(Rect(sX - (sX / 2 + 50),sY - (sY / 2 + 50),100,50), "Continue")){
pressed2 = true;
}
if(GUI.Button(Rect(sX - (sX / 2 + 50),sY - (sY / 2 - 10),100,50), "Quit Game")){
Application.Quit();
}
}
}
Please note that this script is also using the size of the screen for positioning so you can probably ignore all the sX's and sY's XD.
Ok thanks Crazsta, i will try it out in a bit. Im in between classes right now so as soon as i get home i will try it out and see if i can upgrade my script, $$anonymous$$d if i use some of your code as an example for $$anonymous$$e? Yeah my instructor was disappointed i did not make a fully functional pause menu in the time allotted, wish i could learn faster lol.
hey, sorry for the REALLY late reply as I have been insanely busy, but if you used my code that's fine and I'm glad I could help. If you need any more health don't be afraid to ask
Answer by Noztradamuz · Jul 05, 2013 at 07:08 PM
Hello, i don't know what are you exactly trying to do, but i have a similar code in one game that pauses the game and shows a little menu to exit or restar the level, check it out, hope it helps.
//On the Update() function
if (Input.GetKeyDown(KeyCode.Escape) && !isGamePaused)
{
Time.timeScale = 0;
isGamePaused = true;
}
else if (Input.GetKeyDown(KeyCode.Escape) && isGamePaused)
{
Time.timeScale = 1;
isGamePaused = false;
askToRestart = false;
}
//On the OnGUI() function
private void OnGUI()
{
if (isGamePaused && gameStarted)
{
if (!askToRestart)
{
GUI.Box(new Rect(0, 0, Screen.width, Screen.height), "Pausa");
if (GUI.Button(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 10, 90, 20), "Restart"))
{
askToRestart = true;
}
if (GUI.Button(new Rect(Screen.width / 2 , Screen.height / 2 - 10, 90, 20), "Exit"))
{
Application.Quit();
}
}
if (askToRestart)
{
GUI.Box(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 50, 200, 30), "¿Want to restart?");
if (GUI.Button(new Rect(Screen.width / 2 + 5, Screen.height / 2 - 10, 60, 20), "Si"))
{
Application.LoadLevel("GamePlayScene");
}
if (GUI.Button(new Rect(Screen.width / 2 -65, Screen.height / 2 - 10, 60, 20), "No"))
{
askToRestart = false;
}
}
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Unity error "scripts exist in multiple locations" 1 Answer
Networking Problem Please Help!!! [IMPORTANT] 0 Answers
my script says OnCollisionEnter() error bce005 and it wont work 3 Answers
Spawn Script Issue 0 Answers