Moving a gameObject using a GUI button.

Hi,

I’m trying to make a gameobject move when the user presses a gui button. Basically the gameobject is like an airlock door. When the user presses the button i’d like the airlock door to smoothly open.
The code that i’m using at the moment moves the gameobject but it does so instantly. Anyone have any tips?
Here’s what i’ve got so far:

if (GUI.Button(new Rect((Screen.width) - (buttonWidth * 2), (Screen.height) - (buttonHeight * 2), buttonWidth, buttonHeight), "Launch Ship."))
        {
    float amtToMove = currentSpeed * Time.deltaTime;          
    while (airlock1.transform.position.x < 7.4)
    {
	airlock1.transform.Translate(Vector3.right * amtToMove);
    }

}

Try moving your amtToMove logic down in to your translate call.
So:
airlock1.transform.Translate(Vector3.right * currentSpeed * Time.deltaTime);

Your delta time is not able to update the way you have the code. I am not sure if this is causing your issue or not but it is a start. You can try bringing your currentSpeed down to a very small number also so it for sure move small amounts and see if that is your issue.

Why not do it with animation?

Another option is iTween.

But If you really want to use Translate try something like this:

if (GUI.Button(new Rect((Screen.width) - (buttonWidth * 2), (Screen.height) - (buttonHeight * 2), buttonWidth, buttonHeight), "Launch Ship."))
{
LaunchShip = true;
}

Then in the update function:

if(LaunchShip)
{
  if(airlock1.transform.position.x < 7.4)
  {
  amtToMove = currentSpeed * Time.deltaTime;
  airlock1.transform.Translate(Vector3.right * amtToMove);
  }
}

I think this should work.