Input key to translate object

I am trying to make an object translate when a key is pressed for example

function Update () {
if (Input.GetKeyDown (“space”))
print (“space key was pressed”);
}

and

transform.Translate(Vector3(0,0,speed) * Time.deltaTime);

I am not sure what I have done wrong as the combination is not working as planned. I have a smooth mouse orbit on the object as it is required by the client.

Your code is fine, but the Translate instruction isn’t inside the Update - how could you execute that?

Try this:

function Update () { 
   if (Input.GetKeyDown("space")){
      print("space key was pressed");
      transform.Translate(Vector3(0,0,speed) * Time.deltaTime);
   }
}