Prevent GameObject from moving out of the screen

I have this code to move my GameObject around the screen

   if (transform.localPosition.y < Screen.height && Input.GetAxis ("L_YAxis_1") < 0)
        transform.Translate(0, Time.deltaTime * 1256f * GamepadInput.GamePad.GetAxis(GamepadInput.GamePad.Axis.LeftStick, GamepadInput.GamePad.Index.One).y, 0);

    if (transform.localPosition.y > 0 && Input.GetAxis ("L_YAxis_1") > 0)
		transform.Translate(0, Time.deltaTime * 1256f * GamepadInput.GamePad.GetAxis(GamepadInput.GamePad.Axis.LeftStick, GamepadInput.GamePad.Index.One).y, 0);

    if (transform.localPosition.x < Screen.width && Input.GetAxis ("L_XAxis_1") > 0)
					transform.Translate(Time.deltaTime * 1256f * GamepadInput.GamePad.GetAxis(GamepadInput.GamePad.Axis.LeftStick, GamepadInput.GamePad.Index.One).x, 0, 0);

    if (transform.localPosition.x > 0 && Input.GetAxis ("L_XAxis_1") < 0)
					transform.Translate(Time.deltaTime * 1256f * GamepadInput.GamePad.GetAxis(GamepadInput.GamePad.Axis.LeftStick, GamepadInput.GamePad.Index.One).x, 0, 0);

But it doesn’t work in different resolutions. Example: If I run the game in 1920x1200 the GameObject gets out of the screen, but if I tun the game in 800x600 the GameObject doesn’t get out of the screen.

What am I doing wrong? Is there any better way to do this?

Thanks

You are comparing localPosition with Screen.width/height. But localPosition is not the Screen coordinates.
You should first convert position (just position not the localPosition) to screen coordinates using Camera: see Camera.WorldToScreenPoint

and then check them with Screen (by the way you can use Camera.pixelWidth/Height for this).