How do I move a object down when I press space?

The object moves down the correct amount, but it falls when the game starts and not when space is clicked. I also want it to raise back up when space is released. This is the code I wrote:

#pragma strict

var buttonDown = "up";
var moved = 0;

function pressingkey() {
    if (Event.KeyboardEvent("32")) {
        buttonDown = "down";
    } else {
        buttonDown = "up";
    }
}
function button() {
    if (buttonDown === "down" && moved < 10) {
        transform.Translate(Vector3(0,-0.01,0));
        moved = moved + 1;
    } else if (buttonDown === "up" && moved > 0) {
        transform.Translate(Vector3(0,0.01,0));
        moved = moved - 1;
    }
}

function Start () {
    
}

function Update () {
    pressingkey();
    button();
}

Hi

Checking your script the object shouldn’t start falling upon pressing play.

Is this 3D? Does you object have a RigidBody attached with Gravity == On? If so it’ll start falling as soon as you hit play and thus until it hits anything to collide with.

Regards

Koen Matthijs