Use code tags:
else if (transform.eulerAngles.z < -76 | transform.eulerAngles.z > 76) {
fallen = true;
debug = true;
}
Also… don’t use the logical or operator |, use the conditional or operator ||. | forces both to resolve, where || resolves conditionally until it’s satisfied. So basically if z was <-76, it would stop processing since the evaluation is complete. But | would still resolve the >76 regardless.
…
As for why you might be having the issue you’re having. It may be because eulerAngles.z is returning 359.996, instead of -0.004. Both values are technically the same.
What you see in the inspector for a rotation is not necessarily what ‘eulerAngles’ will return. Since ‘eulerAngles’ is just a raw conversion of the quaternion from ‘rotation’, and what is displayed in the inspector is relative to the last input it received.
Your best bet is to normalize your angles into a range that makes sense to you. The one I usually use is -180 to 180:
public static float NormalizeAngle(float angle, bool useRadians)
{
float rd = (useRadians ? PI : 180);
return Wrap(angle, rd, -rd);
}
public static float Wrap(float value, float max, float min)
{
max -= min;
if (max == 0)
return min;
return value - max * (float)Math.Floor((value - min) / max);
}
But keep in mind, if you have rotation in the x or y at all (3d rotation). This will throw it even more in whack, because x rotation around one axis, could be measured as 0 around that same axis and y around some other.
Really… constraining angles by euler measurements can lead to lots of gotchyas in 3d.
If you’re working only in 2d though, you don’t have a lot to worry about aside from normalizing your angle before working with it.