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 /
avatar image
0
Question by Der_Kevin · Nov 06, 2015 at 12:08 PM · uibuttonboolean

Accessing a public Bool from a Ui Button?

Hey, i got a script which looks like this:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using System.IO;
 
 #if UNITY_EDITOR
 using UnityEditor;
 #pragma warning disable 0219
 #pragma warning disable 0162
 #pragma warning disable 0414
 #endif
 
 public class boolz : MonoBehaviour {
 #if UNITY_EDITOR
     
     // states
     public bool editorIsLoading;
     public bool erase;
     private int isRotated;
     private int isRotatedH;
     private bool is2D;
     private bool isOrtho;
     public bool canBuild;
     private bool isCurrentStatic;
     private bool isCamGridMoving;
     private bool isBuildingTC;
     private bool isContinuesBuild;
     private bool isSortingByNameEnabled;
 
     public bool isBuildingMass;
     private bool isMouseDown;
     private bool isInTopView;
 //and so on...

so what i am trying to do is for example activating the "public bool erase;" for example via an UI button. so using the unity event system (that on click() thing from the Button Component) but i can not find the bool in the drop down menu. next question after that would be how can i prevent that two bools are activated, for example "public bool erase;" and "public bool canBuild;" should'nt be active at the same time

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

1 Reply

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

Answer by fafase · Nov 06, 2015 at 12:31 PM

You cannot use instance variable directly, you can pass a static value like either true or false if your method looks like this:

     public void MyMethod(bool value);

But that is not what you want.

You need to pass the script as parameter:

 public void MyMethod(boolz script){
      script. editorIsLoading = ! script. editorIsLoading;
 }

this would switch the value on/off.

So add a script with that method to an object, drag the object to the button listener slot. Then look for the method. You now have a boolz slot showing up. Drag the bool component you want to use in that method.

Comment
Add comment · Show 4 · 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 Der_Kevin · Nov 06, 2015 at 01:48 PM 0
Share

ah, okay. got it. but how do i actually put a reference to the other sript (boolz) to my new script which includes this:

  public void $$anonymous$$y$$anonymous$$ethod(boolz script){
       script. editorIsLoading = ! script. editorIsLoading;
  }

do i need to put something like "public script boolz" on top of the script?

avatar image fafase Der_Kevin · Nov 06, 2015 at 02:20 PM 0
Share

What do you need the reference for? You have the reference to be used within the method.

If you need to use that value later, add a bool and :

     private bool value = false;
    public void $$anonymous$$y$$anonymous$$ethod(boolz script){
        script. editorIsLoading = ! script. editorIsLoading;
       this.value = script. editorIsLoading;
   }

if you need to keep a reference to boolz component, then you don't need to pass it as parameter, just add a reference and drag it.

   public boolz myBoolz;

   public void $$anonymous$$y$$anonymous$$ethod(){
        myBoolz. editorIsLoading = ! myBoolz. editorIsLoading;
   }
avatar image Der_Kevin fafase · Nov 06, 2015 at 02:41 PM 0
Share

ahhh, oh okay, so its better to put this line:

 public void $$anonymous$$y$$anonymous$$ethod(boolz script){
        script. editorIsLoading = ! script. editorIsLoading;
   }

inside the script where the bools (from the first post) are, right? I somehow thought it needs to be a new script, sorry

Show more comments

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

40 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

Related Questions

Unity UI Button Switch Bool? 2 Answers

Changing Color of Material with Bool and Unity UI 1 Answer

Using events to change variables and inherit that value? 0 Answers

Unity UI Button 1 Answer

How To Change Color Of Text On UI When It's Selected | Unity 4.6 3 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