Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
This question was closed May 29, 2016 at 03:41 AM by HavenGaming for the following reason:

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.

avatar image
0
Question by HavenGaming · May 28, 2016 at 06:21 AM · c#scripting problemuiboolean

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

  • Sort: 
avatar image
1

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

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.
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image HavenGaming · May 28, 2016 at 07:35 PM 0
Share

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

Answers Answers and Comments

89 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges