- Home /
Problem with Pause and Pause Menu Script
Hello I'm having some trouble with a pause and pause menu script I'm working on. The scripts themselves work fine but when I test the game the pause menu opens up straight way, without being prompted. Although this happens the resume button is fully functional and I can open and close the pause menu without any trouble. Also upon triggering the pause menu the game itself doesn't pause at all, instead the character continues going forward and passes straight through any other gameobjects as though a collider isn't there.
Here are the scripts, attached to the main camera:
function Update () {
if(Input.GetKey("escape")) {
Time.timeScale = 0;
var script3 = GetComponent("PauseMenuScript");
script3.enabled = true;
}
}
and
var newSkin : GUISkin;
function thePauseMenu() {
GUI.Box(Rect(250, 150, 300, 350), "Pause Menu");
if(GUI.Button(Rect(310, 190, 180, 70), "Resume")) {
Time.timeScale = 1.0;
var script3 = GetComponent("PauseMenuScript");
script3.enabled = false;
}
if(GUI.Button(Rect(310, 290, 180, 70), "Music")) {
Application.LoadLevel(3);
}
if(GUI.Button(Rect(310, 390, 180, 70), "Main Menu")) {
Application.LoadLevel(0);
}
}
function OnGUI () {
GUI.skin = newSkin;
thePauseMenu();
}
thePauseMenu();
I don't know where I went wrong. Thank you for any answers or feedback. - Ben
Answer by m.alekseev · Jul 23, 2012 at 07:23 PM
I didn't understand the first issue. What do you mean, when say 'the pause menu opens up straight way, without being prompted'. And about second: i didn't tested, but I think it's all OK about your character. It passes straight through any other gameobjects because timeScale is zero and, engine doesn't process collision logic. But you can control your character the same way as you can press buttons in menu. So you need to disable your controller script when game is paused.
Thank you, I've added a script to disable the controls. What happens is that the pause menu opens up straight away, as soon as the game starts, without me activating it by pressing escape.
your script is probably enabled to begin. try adding something like
GetComponent("Pause$$anonymous$$enuScript").enabled = false;
in the start function
Your answer
Follow this Question
Related Questions
Pause menu doesn't pause everything 0 Answers
Locked Cursor when Game Paused 1 Answer
Pause menu script, mouse not hiding 1 Answer
Reference a JS script in a C# script? 2 Answers