bool probelems
hey guys i have a problem with this script its for my capture the flag scene but i wanted to get chekker boxes for is flag red or blue
its partly working when i check nothing it is set to blue as i wanted but when i check red than red is true and blue is also true. becouse i got 2 log errors is red and is blue and it should be set to is red :)__Thanks
using UnityEngine;
using System.Collections;
public class CaptureTheFlag : MonoBehaviour {
public bool FlagisRed = false;
void Start()
{
FlagBoolRed();
}
void FlagBoolRed()
{
if (FlagisRed)
{
FlagRed();
}
else {
FlagBlue();
}
}
void FlagRed()
{
Debug.LogError("Flagisset to Red");
}
void FlagBlue()
{
Debug.LogError("Flagisset to Blue ");
}
If a flag has only 2 states: blue & red, you shouldn't need 2 booleans to set its state. A boolean has 2 states as well so just say FlagisRed and you know it's not blue
Answer by ShadyProductions · Jan 23, 2016 at 04:34 PM
As NoseKills mentioned you don't need 2 bools to check for just 2 states.
if (FlagIsRed) {
print("its red");
} else {
print("its blue");
}
Answer by Wesley21spelde · Jan 23, 2016 at 05:14 PM
hey thanks for your explanation. i now tried it like this but still same problem if i check nothing its blue but when i cheack red it is red but it does say blue two
That means you are not correctly assigning the boolean.
Note that by default your flag is blue because it is on false.
Please just think first. Its very logical.
Also how are you calling the function 2 times when its only being called once in your start method.
Note that the start method is only ran once, when the script is first activated in your scene.