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?