Reputation: 759
I have a script that changes the score randomly. A and B. I want the scores to change the button type from false to true depending on the condition. For some reason it won't change.
Unless the scores are even, the last script should continually change the true or false. I also only want these to last until the next button is pushed.
I have printed out the information, so I know the scores are being pulled in they just don't seem to be calculating.
public static bool yayButton = false;
public static bool booButton = false;
ScoreManager.scoreDisplayA;
ScoreManager.scoreDisplayB;
if(ScoreManager.scoreDisplayA > ScoreManager.scoreDisplayB){
yayButton = true;
}
if(ScoreManager.scoreDisplayB > ScoreManager.scoreDisplayA){
yayButton = true;
}
Upvotes: 0
Views: 2389
Reputation: 3469
You set yayButton
to true
in both condition, So this is your first mistake.
With this code once one of your variable become true, it always will be true so I think you need to turn other variable to false.
And this code must be in Update()
or FixedUpdate()
method to detect new change of ScoreManager.
Your final code should be something like this:
public static bool yayButton = false;
public static bool booButton = false;
ScoreManager.scoreDisplayA;
ScoreManager.scoreDisplayB;
void Start()
{
// define the ScoreManager.scoreDisplayA and B here.
// Something like this:
// ScoreManager.scoreDisplayA = GameObject.Find("ScoreManager").GetComponent<scoreDisplayA>();
}
void Update()
{
if(ScoreManager.scoreDisplayA > ScoreManager.scoreDisplayB){
yayButton = true;
booButton = false;
}
if(ScoreManager.scoreDisplayB > ScoreManager.scoreDisplayA){
yayButton = false;
booButton = true;
}
}
Upvotes: 1