I’m having a bit of trouble with this one, considering I got it to work ONE time using the exact C# script I’ve written here.
I’m really lost here, and I’m revisiting beginning C# after a long hiatus.
I have two buttons in my scene on a canvas, in a panel. I am using an empty object in my scene named “ButtonMaster” with a script named “ButtonScript” attached to it.
I have a separate script in my scene named “Bools” attached to an empty gameobject named and tagged as “GameMaster”.
I’m using the two buttons to toggle the boolean values on the GameMaster object.
My On Click() in the button inspector has the “ButtonMaster” object assigned, and then the ButtonScript.ClickedBuryUnbury assigned on button one and ButtonScript.ClickedKillRezz on the second button respectably.
I’ve gotten these buttons to properly toggle the boolean values within the GameMaster object on and off ONE time. (super weird)
Anyhow, here is the script:
using UnityEngine;
using System.Collections;
public class ButtonScript : MonoBehaviour {
private GameObject gameMaster;
private bool killRezzToggle;
private bool buryUnburyToggle;
void Start () {
gameMaster = GameObject.FindGameObjectWithTag ("GameMaster");
killRezzToggle = gameMaster.GetComponent<Bools>().amIDead;
buryUnburyToggle = gameMaster.GetComponent<Bools>().buriedInGround;
}
public void ClickedKillRezz()
{
killRezzToggle=!killRezzToggle;
}
public void ClickedBuryUnbury()
{
buryUnburyToggle=!buryUnburyToggle;
}
}
Can anyone tell me whats going on? Perhaps I’m just coding the toggle incorrectly, but why would it have worked on one occasion? Thanks everyone!