Issue with clamping player to camera view

I’m trying to keep the player within a non-moving camera’s view, so that they can’t take the player off screen, and have it be resolution independent.

So far, the player is limited to the view of the camera. However, if im holding the move button down, the player moves slightly past the stopping point, and when I release the button it moves back to the stopping point. If the player is at the stopping point and I press the same direction key again it will scoot over past slightly and stay there until i release the key, Then it will move back to the limit.

Here is the script controlling the players movement.

using UnityEngine;
using System.Collections;

public class ShipMovement : MonoBehaviour {

	public float moveSpeed = 3.0f;		//Move speed modifier
	public float speedModifier = 1.0f;	//variable to store speed increase bonuses
	private float speedModDuration = 0;
	public float clampOffset = 12.0f;

	// Use this for initialization
	void Start () 
	{

	}
	
	// Update is called once per frame
	void Update ()
	{
		Vector3 screenPos = Camera.main.WorldToScreenPoint(transform.position);

		screenPos.x = Mathf.Clamp(screenPos.x, 0f + clampOffset, Screen.width - clampOffset);

		transform.position = Camera.main.ScreenToWorldPoint(screenPos);
	
		if(Input.GetKey (KeyCode.D))			//Right movement 
		{
			transform.position += Vector3.right * Time.deltaTime * moveSpeed * speedModifier;
		}

		if(Input.GetKey(KeyCode.A))				//Left movement
		{
			transform.position += Vector3.left * Time.deltaTime * moveSpeed * speedModifier;
		}

		if(speedModDuration > 0)		//Decrements timer once activated
		{
			speedModDuration -= Time.deltaTime;
		}
		if(speedModDuration == 0)		//normalizes speed when time is up
		{
			speedModifier = 1.0f;
		}
		if(speedModDuration <0)			//resets timer if it drops below zero, to prevent shorted buffs
		{
			speedModDuration = 0;
		}
	}

	public void AdjustSpeedModifier(float modifier, float time)		//Function to adjust speed modifier
	{
		speedModifier = modifier;
		speedModDuration += time;					//+= allows stackable durations
	}

}

You are calling clamp at the start of your update.

This will correct the position from the last frame.

Move it to the end of the method and you have the behaviour you are expecting.

At the end of line #9 it says = 0;
It should be = 1;