- Home /
Pause Game does not lauch new menu
In my PlayerBehavior.cs file
void Update ()
{
if (Input.inputString.Length>0){
Debug.Log ("Pressed =" + Input.inputString);
}
if (Input.GetKeyDown ("p")) //from Up
{
PauseMenu.isPaused=!PauseMenu.isPaused;
}
}
PauseMenu.cs is as follows:
using UnityEngine;
using System.Collections;
public class PauseMenu : MonoBehaviour {
public static bool isPaused;
public float windowWidth= 256;
public float windowHeight = 100;
public GUISkin newSkin;
enum Menu{None, Pause, Options};
private Menu currentMenu;
// Use this for initialization
void Start () {
isPaused = false;
currentMenu = Menu.None;
}
void OnGUI() {
GUI.skin = newSkin;
Debug.Log ("Inside OnGUI");
if(isPaused && currentMenu == Menu.None)
{
currentMenu = Menu.Pause;
Debug.Log ("Inside isPaused && currentMenu == Menu.None");
}
if(currentMenu == Menu.None)
{
Time.timeScale = 1.0f;
Debug.Log ("Inside currentMenu == Menu.None");
return;
}
Time.timeScale = 0.0f;
switch (currentMenu)
{
case Menu.Options:
Debug.Log ("Inside before ShowOptionsMenu");
ShowOptionsMenu();
break;
case Menu.Pause:
Debug.Log ("Inside before ShowPauseMenu");
ShowPauseMenu();
break;
}
}
Looks like inside OnGUI() function on PauseMenu.cs IsPause=false to cause Menu.Options never to be true from Main_Menu scene that includes PlayerBehavior.cs script. Any idea what is causing this?
Answer by NerdGameStudio · May 31, 2015 at 12:32 PM
You are changing a variable after changing the timeScale. The variable you are trying to change is framerate dependent, so your variable will never ever change when the ingame time has "stopped", or in other words == 0. I cannot think of a workaround at the moment I'm affraid. But this is what's causing your problem.
Your answer
Follow this Question
Related Questions
When Active Toggle X 1 Answer
item pick up menu 1 Answer
Using keyboard to control a dialog/shop 1 Answer
GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced) 0 Answers
Game stopping at Pause? 1 Answer