Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
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.

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

Notes or Bubble Window for Variables in Inspector Giving Help? 3 Answers

Adding variables to inspector strings 1 Answer

A code to reset a variable after x time if another button is not pressed. Help! 2 Answers

Is there a better way to access the single active Toggle in a ToggleGroup? 4 Answers

Unity UI 4.6 Canvas Enable/Disable make Accessible 2 Answers


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