- Home /
The question is answered, right answer was accepted
SOLVED : Why is this bool not changing?
In the following code, my boolean variable "bIsOvertaking" is NEVER triggered, despite the correct message printing. The IF/ELSE statement is certainly working but I can't for the life of me figure out why this bool isn't switching to true.
function AvoidCollision()
{
var hit : RaycastHit;
var RayStartPos_FL : Vector3 = Ray_Emitter_FL.transform.position;
var RayStartPos_FR : Vector3 = Ray_Emitter_FR.transform.position;
if (Physics.Raycast (RayStartPos_FL, transform.forward, hit, fBrakeTriggerDistance) ||
Physics.Raycast (RayStartPos_FR, transform.forward, hit, fBrakeTriggerDistance))
{
if (hit.transform.tag == "Car")
{
// Do braking
if (!bCarDoesOvertake)
{
bIsBraking = true;
print ("Car in front - braking!");
}
// Do overtaking
else
{
bIsOverTaking = true;
print("Car in front - overtaking!");
}
}
}
else
{
bIsBraking = false;
print ("Road clear");
Debug.DrawRay (RayStartPos_FL, transform.forward * fBrakeTriggerDistance, Color.green);
Debug.DrawRay (RayStartPos_FR, transform.forward * fBrakeTriggerDistance, Color.green);
}
}
Which is 'the correct' message - are you saying this is printed print("Car in front - overtaking!"); ? If it is, then something is immediate flipping it back, perhaps in other code
Yeah, the overtaking message. No other code even touches that bool. I'd only just put it in and was wanting to test overtaking before putting in the code to turn it off. This makes no sense...
HAHAHAHA, it's the capital T in the variable name. For some odd reason, Unity wasn't giving me an error. Fixed. head slap