Basic moving script!

For anyone who is starting off with Unity I put this simple moving script you can attach to your object

var speed = 10;
var player:Rigidbody;

function Start(){
player=transform.rigidbody;
}

function Update(){

if (Input.GetKey ("up")){
player.AddForce (transform.forward * speed);
Debug.Log("iWoundPwn says you're moving");
}

if (Input.GetKey ("down")){
player.AddForce (transform.forward * -speed/1.2);
Debug.Log("iWoundPwn says you're stopping");
}

if (Input.GetKey ("left")){
player.AddForce (transform.right * -speed);
Debug.Log("iWoundPwn says you're moving left");
}

if (Input.GetKey ("right")){
player.AddForce (transform.right * speed);
Debug.Log("iWoundPwn says you're moving right");
}

if (Input.GetKey ("w")){
player.AddForce (transform.forward * speed);
Debug.Log("iWoundPwn says you're moving");
}

if (Input.GetKey ("s")){
player.AddForce (transform.forward * -speed/1.2);
Debug.Log("iWoundPwn says you're stopping");
}

if (Input.GetKey ("a")){
player.AddForce (transform.right * -speed);
Debug.Log("iWoundPwn says you're moving left");
}

if (Input.GetKey ("d")){
player.AddForce (transform.right * speed);
Debug.Log("iWoundPwn says you're moving right");
}
}

please let me know if you get any errors! Thanks.

Here is something shorter that does the same thing, though it is a little more advanced. I’m not sure if there are any errors in this, I just pulled it from a script i’m using for a project that had alot of other mixed in code with it.

var rotateSpeed = 3;
var speed = 3;
function Update (){
var controller : CharacterController = GetComponent(CharacterController);
transform.Rotate(0, Input.GetAxis (“Horizontal”) * rotateSpeed, 0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis (“Vertical”);
controller.SimpleMove(forward * curSpeed);
}
@script RequireComponent(CharacterController)

The OP’s script has spelling errors, and floods the console with prints. Not great

You don’t need to print your name every time, something a kid would do when they first start programming.

Thats true but you can take the prints off, no spelling errors that I saw let me check.

foward, and possibly lowercase update and start, but that might be accepted