I'm developing a game in Unity using C#. A part of the code, using a boolean, decides if the player is allowed to buy an upgrade for a building or not. If he is, the integer of the building is increased by 1. Next to that, the boolean gets set to false. If he isn't, nothing happens at the moment.
There is a button in game, functionally increasing the week number by 1, allowing the player again to be able to upgrade building (thus setting the boolean true again).
The problem is that after buying the upgrade, the boolean is set to false, and even when I set it back to true again, when I try to upgrade the building, the boolean appears to be false. I also tried to check it with the help of an integer instead of a boolean (using the values 0 and 1), but the problem is still here.
Here is some code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ActivateTrigger : MonoBehaviour
{
public int transtech = 0;
public int factech = 0;
public bool facmag = true;
public bool transmag = true;
void OnGUI () {GUI.Box(new Rect(0, Screen.height - 120 - 60, 150, 30), "Week: " + week.ToString());
if (GUI.Button(new Rect(0, Screen.height - 120 - 30, 150, 20), "Continue one week"))
{
NextProcess();
}
if (GUI.Button(new Rect(20, 70, 120, 20), "Koop upgrade") )
{
Debug.Log("Facmag: " + facmag);
if (facmag == true)
{
facmag = false;
}
}
void NextProcess()
{
Debug.Log("Next process called");
facmag = true;
transmag = true;
Debug.Log("Facmag: " + facmag);
}
}
So, when NextProcess() is called, the Debug Log shows the value being true. But after the first time buying the upgrade, no matter if I pressed the button to execute NextProcess() or not, the value stays false. I'm wondering if I missed something completely or not. No other code in this class uses the booleans, nor do any of the few other classes I've got do. So where lies the problem?