Guess the experienced peeps are to good for the help room. Too busy crying about noobs. Some of Us don't want you to fix our script but guide us through what we do not understand. Thanks for the discouragement.
How Can i Get This bool to work? Just need someone willing to explain.
How do I set up a bool, that has three questions instead of two? I have a main menu, a pause menu, and the player UI. Normally if main menu is showing then it's true while pause would be false, and vice versa. So how would I go about it with all three? I am still pretty new to scripting, and the bools always get me. Maybe I over think it. Just need explained steps so I can understand it more fully. The MenuTransitions is the script I am trying to get the bool to work, seeing as I do not quite understand bools anyway, its been hard. The ShowPanelsMenu is the script I am calling from. If one of the three is true then the two other should be false, and I need this for each one: the menu, the pausemenu, and the playerUI. Am I doing the bool right?
Menu Transitions
using UnityEngine;
using System.Collections;
public class MenuTransitions : MonoBehaviour {
public bool mainMenu;
public bool pauseMenu;
public bool playerUI;
private ShowPanelsMenu showPanelsMenu;
void Awake ()
{
showPanelsMenu = GetComponent<ShowPanelsMenu>();
}
public void MainMenu ()
{
if (mainMenu = true) {
showPanelsMenu.ShowMainMenuPanel ();
showPanelsMenu.HidePausePanel ();
showPanelsMenu.HidePlayerUIPanel ();
}
else
{
if (mainMenu = false)
{
showPanelsMenu.HideMainMenuPanel ();
}
}
}
public void PauseMenu ()
{
if (pauseMenu = true) {
showPanelsMenu.ShowPausePanel ();
showPanelsMenu.HideMainMenuPanel ();
showPanelsMenu.HidePlayerUIPanel ();
}
else
{
if (pauseMenu = false) {
showPanelsMenu.HidePausePanel ();
}
}
}
public void PlayerUI ()
{
if (playerUI = true) {
showPanelsMenu.ShowPlayerUIPanel ();
showPanelsMenu.HidePausePanel ();
showPanelsMenu.HideMainMenuPanel ();
}
else
{
if (playerUI = false) {
showPanelsMenu.HidePlayerUIPanel ();
}
}
}
}
ShowPanelsMenu
using UnityEngine;
using System.Collections;
public class ShowPanelsMenu : MonoBehaviour {
public GameObject mainMenuPanel;
public GameObject pausePanel;
public GameObject playerUIPanel;
//Call this function to activate and display the main menu panel
public void ShowMainMenuPanel()
{
mainMenuPanel.SetActive (true);
}
//Call this function to deactivate and hide the main menu panel
public void HideMainMenuPanel()
{
mainMenuPanel.SetActive (false);
}
//Call this function to activate and display the Pause panel
public void ShowPausePanel()
{
pausePanel.SetActive (true);
}
//Call this function to deactivate and hide the Pause panel
public void HidePausePanel()
{
pausePanel.SetActive (false);
}
//Call this function to activate and display the Player UI
public void ShowPlayerUIPanel()
{
playerUIPanel.SetActive (true);
}
public void HidePlayerUIPanel()
{
playerUIPanel.SetActive (false);
}
}
I kind of understand what your saying @vittu1994. Like I said I am still quite new to Bools. Every tut I see does not really explain the methods of bool. It has been holding me back not fully understanding the bool when a lot of things use it. I appreciate any help explained.
Answer by vittu1994 · May 28, 2016 at 08:50 AM
Better to have 3 different bools for each 3 UI. Have different conditions for when a certain UI is true like
public bool menuUI = false, pauseUI = false, gameUI = false;
when you want to access lets say the menu UI, you just have all the other bools set to false and have menu UI set to true. And when you access other UI have the condition that all other bools need to be false in order for this to happen.
And how to activate UI:
menuUI.SetActive(true);
and when you want to disable just set to false
Answer by Gobaz · May 28, 2016 at 08:47 AM
I would use an enum instead, since booleans are used for true and false. Something like this:
public enum GameState
{
Menu,
Game,
Inventory
}
Then you could use it like this:
private GameState gameState;
// Set this if you go to menu.
gameState = GameState.Menu;
// Set this if you go to game.
gameState = GameState.Game;
// Set this if you go to inventory.
gameState = GameState.Inventory;
//Then just check the value whenever you need
if(gameState == GameState.Menu)
//Do stuff in menu.
if(gameState == GameState.Game)
//Do stuff in game.
if(gameState == GameState.Inventory)
//Do stuff in inventory.
I'm not sure how that would work, I don't know much of enum yet. Still pretty new. Lmao. Would everything be turned off until called with that?
Follow this Question
Related Questions
Certain scripts that are attached does not work after build, scene change and closing unity 0 Answers
How to change the Bool for only a single prefab GameObject creating with Instantiate? 2 Answers
How to send event to my canvas via script 0 Answers
Always pickup closest item? 0 Answers
I get a "NullReferenceException" when trying to change the text of a UI text box. 1 Answer