I’m trying to limit a sphere’s X position by using Mathf.Clamp but I can’t see what I’m doing wrong. Here’s my code:
PlayerPos = gameObject.transform.position;
// Screen Aspect Ratio Check
bool AR169 = ScreenAspect == 16f / 9f;
bool AR1610 = ScreenAspect == 16f / 10f;
bool AR219 = ScreenAspect == 21f / 9f;
bool AR54 = ScreenAspect == 5f / 4f;
bool AR43 = ScreenAspect == 4f / 3f;
bool AR32 = ScreenAspect == 3f / 2f;
//Clamp X coordinate according with screen aspect ratio
if (AR169 == true) {
Mathf.Clamp (PlayerPos.x, -3.75f, 3.75f);
} else if (AR1610 == true) {
Mathf.Clamp (PlayerPos.x, -3.4f, 3.4f);
} else if (AR219 == true) {
Mathf.Clamp (PlayerPos.x, -4.9f, 4.9f);
} else if (AR43 == true) {
Mathf.Clamp (PlayerPos.x, -2.85f, 2.85f);
} else if (AR54 == true) {
Mathf.Clamp (PlayerPos.x, -2.65f, 2.65f);
} else if (AR32 == true) {
Mathf.Clamp (PlayerPos.x, -3.17f, 3.17f);
}
gameObject.transform.position = PlayerPos;
Tried using the above in both Start() and Update() to no effect. The sphere doesn’t stop at the designated coordinates.