clamp input.acclereation within screen width

I’m making a game where you should move your player on an android device by using the input.acclereation functtion.
The player moves only on the x.axis, it works good.
My problem is, that the player is running out of the screen on left and right side of the x axis.
I tried to clamp the movement to the screen width, it works either but not very smoothly.
If the player touches the screen border and you want to go to the other side it jumps from the wall instead from moving to the other site.

Here ist my code:

float targetSpeed;
targetSpeed = Mathf.Clamp (Input.acceleration.x, -0.25f, 0.25f);

Vector3 ObjectScreenPosition = Camera.main.WorldToScreenPoint (transform.position);
float maxwidthRight = (Screen.width - 30);
float maxwidthLeft = (Screen.width - Screen.width + 57);

if (ObjectScreenPosition.x >= maxwidthRight) {
	targetSpeed = Mathf.Clamp (Input.acceleration.x, -0.2f, 0f);
      } else if (ObjectScreenPosition.x <= maxwidthLeft) {
 	targetSpeed = Mathf.Clamp (Input.acceleration.x, -0f, 0.2f);
transform.Translate (targetSpeed * speed * 145, transform.position.y, transform.position.z);

Do you have any sugestions for me to do it in a better way ? Or an idea to fix my “bounce” problem ?
Thanks !

The Problem is solved, i changed three things.

  1. Changeds the suggestions from FortisVenaliter
  2. Changeds the suggestions from fabian.mkv
  3. I added this code in the start section of my script:
    transform.position = new Vector3 (0, 0, 0);

Maybe one of these or alle three together fixes the problem, thanks for help.

Thanks for the suggestions i’ll figure out your code and will give an Update.