Before I begin, my apologies if this question has been answered before: I've searched around but unfortunately could not find an answer.
I know the basics of GUIToggle, and I know to use it with a Button style in order to create a GUIToggle disguised as an "On/Off" button.
I'm working on a project with a few other people and in this project I made a main menu screen with selectable entries using several GUIToggle calls. When the project is run, if the user starts the game (detected through GUIToggle), another scene is loaded (the GameObject that has the menu screen MonoBehavior and screen management is set to not be destroyed between scenes) and the player gets in-game.
Now, I implemented a pause menu using the same concept that was used in the main menu: GUIToggle calls for the various entries of the pause menu. The same button style of the main menu is used in this one. When I hover the mouse over the entries, the toggles correctly use the OnHover texture I assigned in the GUISkin custom styles I created (used in the main menu as well), so everything seems to work fine. However, when I try to click on one of the GUIToggle, it simply does not register the click!
I'm doing the GUIToggle calls inside OnGUI(), and I've tested mouse clicks from the Input class, and the clicks are being registered there.
Before I try to use my hammer to get this to work (thought about manually checking Rect coordinates when a mouse click occurs), I wanted to know if (I'm quite sure it's something right under my nose) there might be any sort of MonoBehavior (that I'm unaware of) in the project that may be inhibiting GUIToggle from returning true on this pause menu... Something that conflicts with my (supposedly) correct use of GUIToggle.
Thanks for your time.
EDIT: here's the relevant conde at the moment:
void OnGUI()
{
if (IsActive)
{
GUI.skin = _screenManager.MenuSkins;
_sizer.BeginGUI();
// Debug.Log(_screenManager.CurrentState.ToString());
if (_screenManager.CurrentState.Equals(ScreenManager.ScreenState.Paused))
{
GUI.DrawTexture(_menuBox, _menuBoxBackground, ScaleMode.StretchToFill, true);
GUI.Label(_titleRect, "Game Paused", _titleStyle);
// Debug.Log(_screenManager.CurrentState);
if ((bool)(_buttonStates[(int)ButtonID.ResumeGame] = GUI.Toggle(
(Rect)_buttonRects[(int)ButtonID.ResumeGame], (bool)_buttonStates[(int)ButtonID.ResumeGame],
(string)_buttonTexts[(int)ButtonID.ResumeGame], _buttonStyle)))
{
Debug.Log("Resume Game pressed");
_buttonStates[(int)ButtonID.ResumeGame] = false;
UnPause();
}
else if ((bool)(_buttonStates[(int)ButtonID.Options] = GUI.Toggle(
(Rect)_buttonRects[(int)ButtonID.Options], (bool)_buttonStates[(int)ButtonID.Options],
(string)_buttonTexts[(int)ButtonID.Options], _buttonStyle)))
{
Debug.Log("Options pressed");
_buttonStates[(int)ButtonID.Options] = false;
// _screenManager.CurrentState = ScreenManager.ScreenState.Options;
//TODO create and configure an Options screen
}
else if ((bool)(_buttonStates[(int)ButtonID.ReturnToMenu] = GUI.Toggle(
(Rect)_buttonRects[(int)ButtonID.ReturnToMenu], (bool)_buttonStates[(int)ButtonID.ReturnToMenu],
(string)_buttonTexts[(int)ButtonID.ReturnToMenu], _buttonStyle)))
{
_screenManager.CurrentState = ScreenManager.ScreenState.MainMenu;
_buttonStates[(int)ButtonID.ReturnToMenu] = false;
Debug.Log("Return to menu pressed");
}
}
_sizer.EndGUI();
}
}
private void UnPause()
{
Debug.Log("Unpaused!");
_screenManager.CurrentState = ScreenManager.ScreenState.InGame;
Time.timeScale = _defaultTimeScale;
_defaultFixedTimeDelta = Time.fixedDeltaTime;
Object[] objects = FindObjectsOfType(typeof(GameObject));
Debug.Log(objects.Length);
foreach (GameObject go in objects)
{
if (go != this)
go.SendMessage("OnResumeGame", SendMessageOptions.DontRequireReceiver);
}
}
// Update is called once per frame
void Update()
{
if (IsActive)
{
if (_screenManager.CurrentState.Equals(ScreenManager.ScreenState.InGame))
{
if (Input.GetMouseButtonDown(0))
{
Debug.Log("Mouse click detected");
// do something
}
if (Input.GetKey(KeyCode.Escape))
{
_screenManager.CurrentState = ScreenManager.ScreenState.Paused;
Time.timeScale = 0;
_defaultFixedTimeDelta -= _defaultTimeScale;
Debug.Log("Game paused!");
Object[] objects = FindObjectsOfType(typeof(GameObject));
Debug.Log(objects.Length);
foreach (GameObject go in objects)
{
if(go != this)
go.SendMessage("OnPauseGame", SendMessageOptions.DontRequireReceiver);
// Debug.Log(go.ToString());
}
}
}
else if (_screenManager.CurrentState.Equals(ScreenManager.ScreenState.Paused))
{
if (Input.GetMouseButtonDown(0))
{
Debug.Log("Mouse click detected");
// do something
}
if (Input.GetKey(KeyCode.Escape))
{
UnPause();
}
}
}
}
↧