I have a button to toggle the active state of various GameObjects off and on. The only object that actually toggles off and on is the “Worker” object. None of the others toggle. Is there anything you see that would cause this? I’ve looked at all the other objects and scripts and nothing is referencing these objects to keep them in a certain active state. Another weird thing to note, the gameObject script is on is active on start, but Debug.Log for ActiveState doesn’t display in the console.
public class ManageModeButton2 : MonoBehaviour
{
[SerializeField]
GameObject ManageGrid;
[SerializeField]
GameObject ManageModeMenu;
[SerializeField]
GameObject Plant;
[SerializeField]
GameObject SellButton;
[SerializeField]
GameObject UpgradeButton;
[SerializeField]
GameObject PlotTilesButton;
[SerializeField]
GameObject BuildingsButton;
[SerializeField]
GameObject BuildModeButtonObject;
[SerializeField]
GameObject PlotSelectionButton;
[SerializeField]
GameObject RouteSelectionButton;
[SerializeField]
GameObject HireWorkersButton;
private GameObject[] Workers;
private GameObject[] ManageModeWorkers;
private GameObject Player;
public static bool ActiveState;
private void Start()
{
ActiveState = true;
Workers = GameObject.FindGameObjectsWithTag("Worker");
ManageModeWorkers = GameObject.FindGameObjectsWithTag("ManageModeWorker");
Player = GameObject.FindGameObjectWithTag("Player");
ManageModeMenu.SetActive(!ActiveState);
ManageGrid.SetActive(!ActiveState);
Debug.Log(ActiveState);
}
public void ManageModeButton()
{
ActiveState = !ActiveState;
foreach (GameObject Worker in Workers)
{
Worker.SetActive(ActiveState);
}
foreach (GameObject Worker in ManageModeWorkers)
{
Worker.SetActive(!ActiveState);
}
Player.SetActive(ActiveState);
Plant.SetActive(ActiveState);
SellButton.SetActive(ActiveState);
UpgradeButton.SetActive(ActiveState);
BuildModeButtonObject.SetActive(ActiveState);
ManageModeMenu.SetActive(!ActiveState);
PlotSelectionButton.SetActive(!ActiveState);
RouteSelectionButton.SetActive(!ActiveState);
HireWorkersButton.SetActive(!ActiveState);
ManageGrid.SetActive(!ActiveState);
}
}