Problem with Update()!

Hello everyone!

I am a noob here at Unity. I just read Holistic Game Development with Unity by Penny de Byl and I thought I would test myself on all the topics. My idea was to create a small 2D shoot em up where you had a small AI controlled ship that would follow your ship around and try to shoot it. You had to avoid it for as long as you could, and when you died it would show you how long you survived. I have this much done:

#pragma strict

var moveSpeed: double = 0.3;
var rotateSpeed: double = 3;

function Start () {

}

function Update () {

	if(Input.GetKeyDown("up")) {

		this.transform.Translate(Vector3.forward * moveSpeed);
	
	}
	
	if(Input.GetKeyDown("right")) {
	
		this.transform.Rotate(Vector3.up, rotateSpeed);
	
	}
	
	if(Input.GetKeyDown("left")) {
	
		this.transform.Rotate(Vector3.up, -rotateSpeed);
	
	}

}

This is the moving script for the player’s rocket. It works fine, but it won’t loop the translate! (meaning I have to hit up over and over if I want it to move) What I want to have happen is that I want it so that you can just press and hold the up key and it will continuously move you forward. Same with the rotating.

If anyone could help, I would deeply appreciate it.

If I missed anything that you need to know in order to answer, just ask!

Thanks a lot!

-Silent

EDIT::::::::::::

Woops! Incorrect code. I fixed it for anyone who looked at it earlier and might have been saying “what the?”

Use GetKey instead of GetKeyDown, though GetAxis would be easier. Also you need to use Time.deltaTime. Also, don’t bother with double, just use float. Unity doesn’t use doubles for anything internally, only floats, so it’s being converted to float anyway and you don’t gain anything. (You’d only need double if you were doing some high-precision math.)

–Eric

Thanks so much! I thought I had tried that when I first read your answer, but I guess I hadn’t!

Thanks again!