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 hostShadows · Mar 27, 2015 at 09:24 PM · referencing

trouble with referencing a componenet (bool)

I was trying to be able to reference a bool so when i click on an object, the script's bool that's attached to the object turns from false to true, and another script recognizes it and prints out a line of code (here are my two scripts) using UnityEngine; using System.Collections;

 using UnityEngine;
 using System.Collections;
 
 public class BlackClick : MonoBehaviour 
 {
     public bool buttonSwitcher1 = false;
     
     
     // Use this for initialization
     void awake ()
     {
         
     }
     
     void Start () 
     {
         
         
     }
     
     // Update is called once per frame
     void Update () 
     {
         
         
     }
     
     void OnMouseUp ()
     {
         if (tag == "BlackButton 1") 
         {
             Debug.Log ("Button1's bool is set to true");
             buttonSwitcher1 = true;
             
         } 
         
     }
 }
 

and

 using UnityEngine;
 using System.Collections;
 
 public class ButtonManager : MonoBehaviour 
 {
 
     public GameObject blackButtonReturnBool1;
 
     private BlackClick blackClick;
 
     public Transform whiteButton1;
 
     public Transform blackButton1;
 
     public Transform buttonSlot1;
 
     public bool buttonSwitch1 = false;

 
 
     void Awake ()
     {
         blackClick = blackButtonReturnBool1.GetComponent<BlackClick> ();
     }
 
     // Use this for initialization
     void Start () 
     {
         GameObject whiteSpawn1 = Instantiate(whiteButton1, buttonSlot1.position, buttonSlot1.rotation) as GameObject; // the script BlackClick is attached to this whitebutton1 object that will spawn
         
     }
     
     // Update is called once per frame
     void Update () 
     {
 
         if (blackClick.buttonSwitcher1 == true) 
             {
              Debug.Log ("Button 1 was switched to black");
             }
         
     
     }
     
 
 }
 

my ButtonManager is set to an empty object and my BlackClick is set to the "whiteButton1" that spawns. When "whiteButton1" is clicked, BlackClick (the script attached to it) will print it's debug log "Button1's bool is set to true" but ButtonManager's debug log "button 1 was switched to black" won't print out. Does anyone have any idea as to why the if statement wasn't called?

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

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

Answer by JigneshKoradiya · Mar 27, 2015 at 09:42 PM

using UnityEngine; using System.Collections;

public class BlackClick : MonoBehaviour {

 void OnMouseUp ()
  {
      if (tag == "BlackButton 1" && buttonSwitcher1==false) 
      {
          Debug.Log ("Button1's bool is set to true");
          buttonSwitcher1 = true;
          
      } 
      
  }

}

and

using UnityEngine; using System.Collections;

public class ButtonManager : MonoBehaviour {

  public GameObject blackButtonReturnBool1;
 
  private BlackClick blackClick;

void Update () {

      if (blackClick.buttonSwitcher1 == true) 
          {
           Debug.Log ("Button 1 was switched to black");
           blackClick.buttonSwitcher1=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 hostShadows · Mar 29, 2015 at 03:04 PM

the if statement wont run, "Button 1 was switched to black" wont print, on my other object, blackClick's bool will be set to true, but it wont run my if statement on my game manager object..

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 hostShadows · Mar 29, 2015 at 10:49 PM 0
Share

i was having a problem doing this because only BlackClick's debug log was printing, but i was doing this with multiple bools. So i deciding to flip it around and make black click reference button manager, thank you for the help!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Referencing all objects in scene 2 Answers

Having trouble referencing a script 2 Answers

How can i reference the scripts of multiple Instantiated GameObjects? 3 Answers

This makes no sense help, pls help 1 Answer

Using a Scriptable Object as a Config 0 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