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();
}