'Unity compiler thinks my position value is a bool?
I'm attempting a hare-brained method of camera handling that doesn't involve collisions but just assigns boundaries in the context of a simple box world with two spheres bouncing around, one of which is the player. This is the code that I am attempting to run as my CameraFollow script:
public Transform player;
public Vector3 offset;
void Update()
{
Vector3 defaultPosition = player.position + offset;
if (-497.5f <= defaultPosition.x <= 497.5f) {
transform.position.x = defaultPosition.x;
}
else if (defaultPosition.x < -497.5f) {
transform.position.x = -497.5f;
}
else if (defaultPosition.x > 497.5f) {
transform.position.x = 497.5f;
}
if (-497.5f <= defaultPosition.z <= 497.5f) {
transform.position.z = defaultPosition.z;
}
else if (defaultPosition.z < -497.5f) {
transform.position.z = -497.5f;
}
else if (defaultPosition.z > 497.5f) {
transform.position.z = 497.5f;
}
if (0.5f <= defaultPosition.y <= 1499.5f) {
transform.position.y = defaultPosition.y;
}
else if (defaultPosition.y < 0.5f) {
transform.position.y = 0.5f;
}
else if (defaultPosition.y > 1499.5f) {
transform.position.y = 1499.5f;
}
}
}
The walls are at X +/- 500 with scale of 5, so 2.5 radius, thus the +/-497.5 Ceiling and floor have scale of 1, floor is at 0, Ceiling is at 1500. You get the picture.
The issue I'm having is that the Unity compiler (but not VSCode with Unity and C# plugins installed) is telling me that "the '<=' operator cannot be used on operands of type 'bool' and 'float'". Can anyone explain to me where this boolean value is coming from? The only booleans I can even see implied in this code are the output of the conditions of the if statements, but this boolean seems to be inside the conditions somehow. I'm confused.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
