Move object forward 1 unit then stop

I’m building an animated main menu for my game and I was wondering how I would get it so that when the mouse hovers over the object it moves forward 1 unit, and stops. No more, I have only got it so that it will keep moving forward while the mouse is on it. The only other solution I can think of is placing an invisible wall that it will stop on contact. But if anyone has a proper solution I’d be ecstatic to hear it! Here’s my code!

var pLight: Transform;


private var enableLight: boolean = false;
pLight.light.enabled = false;

function OnMouseOver () {
    renderer.material.color -= Color(0, 0, 100) * Time.deltaTime;
    
    pLight.light.enabled = true;
    
}

function OnMouseExit () {
pLight.light.enabled = false;

}
function OnMouseEnter(){
  transform.position.z += 1; //Change to x if you prefer
}

Hope that works for you.

You could try this:

  var currentPosition : Vector3;
  var moveDirection : Vector3 = Vector3(0,0,1); //For example
  var t : float;

  function OnMouseEnter() {
       currentPosition = transform.position;
       t = 0;
  }

  function OnMouseOver() {
       t = Mathf.Clamp01(Time.deltaTime + t);
       transform.position = currentPosition + (moveDirection * t);
  
  }

  function OnMouseExit() {
      transform.position = currentPosition;
  }