• 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 /
avatar image
0
Question by Jotakuun · Apr 27, 2015 at 10:05 AM · uibuttonvariableinspector

Script variable doesn't appear in UI's inspector

Hello Unity Community!,

I'm trying to turn off a boolean variable in UI's inspector. I'm using Unity 5, and I don't know what I'm doing wrong. What should I do?

This is the variable.

 #pragma strict
 var MainMenu : GameObject;
 var MainMenuON : boolean = true;
 
 function Start () {
 }
 
 function Update () {
     if(MainMenuON){
         MainMenu.SetActive (true);
     }
     else if(!MainMenuON){
         MainMenu.SetActive (false);
     }
 }

alt text

Comment
Add comment · Show 4
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 PvTGreg · Apr 27, 2015 at 10:40 AM 0
Share

where are you declaring it? please show the entire script

avatar image Jotakuun · Apr 27, 2015 at 10:58 AM 0
Share

edited, thank you

avatar image Umresh · Apr 28, 2015 at 01:50 PM 1
Share

you have to create a public function to make your boolean false on the button click. I guess you know how to do that.

avatar image fffMalzbier · Apr 28, 2015 at 02:41 PM 0
Share

Its kind of wired that you can set a bool from another scirpt like useGUILayout in the screenshot but not your own variable of type bool.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by KdRWaylander · Apr 28, 2015 at 02:42 PM

Hi,

Change:

 var MainMenuON : boolean = true;

To:

 public var MainMenuON : boolean = true;

Even if JS assumes it's a public one when you declare a variable, you have to specify it to actually make it appear in the hierarchy.

On the contrary, if you wanna hide in inspector a (specificly) public variable, you have to add @HideInInspector in front of your variable !

 @HideInInspector public var myBool : boolean = true;

EDIT: And if I may, to simplify your code, instead of:

 if(MainMenuON){
    MainMenu.SetActive (true);
 }
 else if(!MainMenuON){
    MainMenu.SetActive (false);
 }

you can only use:

 MainMenu.SetActive (MainMenuON);



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 Jotakuun · Apr 29, 2015 at 09:22 AM 0
Share

This works, thank you.

avatar image
1

Answer by brunopava · Apr 28, 2015 at 02:44 PM

Also, you need to toggle your boolean to false and true. Like this:

 public function Toggle()
 {
      if(MainMenuON){
          // if its active, then deactivate
          MainMenuON = false;
          MainMenu.SetActive (false);
      }
      else{
          // if its deactivated, then activate
          MainMenuON = true;
          MainMenu.SetActive (true);
      }
 }
 

Then just choose this function on the inspector.

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 Jotakuun · Apr 29, 2015 at 09:23 AM 0
Share

This works too, thank you.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

23 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

Related Questions

Restart button not functioning properly 4 Answers

Custom Inspector - How to add functionality? 1 Answer

Parent Class variables in Child Class's Inspector (C#) 0 Answers

Placing scene object in inspector as a varable and load with button in game 1 Answer

Unity 4.6's button Bug? 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