How to limit game object's world position?

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.

That’s because you’re not assigning the clamped value returned by Mathf.Clamp anywhere. You want something like this instead:

     float clampedX = PlayerPos.x;

     if (AR169 == true) {
         clampedX  = Mathf.Clamp (PlayerPos.x, -3.75f, 3.75f);
     } else if (AR1610 == true) {
         clampedX  = Mathf.Clamp (PlayerPos.x, -3.4f, 3.4f);
     } else if (AR219 == true) {
         clampedX  = Mathf.Clamp (PlayerPos.x, -4.9f, 4.9f);
     } else if (AR43 == true) {
         clampedX  = Mathf.Clamp (PlayerPos.x, -2.85f, 2.85f);
     } else if (AR54 == true) {
         clampedX  = Mathf.Clamp (PlayerPos.x, -2.65f, 2.65f);
     } else if (AR32 == true) {
         clampedX  = Mathf.Clamp (PlayerPos.x, -3.17f, 3.17f);
     }

     gameObject.transform.position = new Vector3(clampedX, PlayerPos.y, PlayerPos.z);

You have to assign the Return value of the Clamp function. Like this:

PlayerPos.x = Mathf.Clamp(PlayerPos.x, -3, 3);