system
1
I wrote this script so that my character could move up down left and right, yet it gives me an error when I add it into unity.
Thanks for any help!
#pragma strict
function Start () {
}
function Update () {
if
(var xI : float = Input.GetKeyDown (KeyCode.A) * Time.deltaTime * 0.5);
transform.Translate (Vector3(xI,0,0));
if
(var xII : float = Input.GetKeyDown (KeyCode.D) * Time.deltaTime * -0.5);
transform.Translate (Vector3(xII,0,0));
if
(var yI : float = Input.GetKeyDown (KeyCode.W) * Time.deltaTime * 0.5);
transform.Translate (Vector3(0,yI,0));
if
(var yII : float = Input.GetKeyDown (KeyCode.S) * Time.deltaTime * -0.5);
transform.Translate (Vector3(0,yII,0));
}
#pragma strict
function Start () {
}
function Update () {
if
(var xI : float = Input.GetKeyDown ("A") * Time.deltaTime * 0.5);
transform.Translate (Vector3(xI,0,0));
if
(var xII : float = Input.GetKeyDown ("D") * Time.deltaTime * -0.5);
transform.Translate (Vector3(xII,0,0));
if
(var yI : float = Input.GetKeyDown ("W") * Time.deltaTime * 0.5);
transform.Translate (Vector3(0,yI,0));
if
(var yII : float = Input.GetKeyDown ("S") * Time.deltaTime * -0.5);
transform.Translate (Vector3(0,yII,0));
}
codeings not my strong suit but this should work
var speed : float = 1;
var h :float = Input.GetAxis(“Horizontal”);
var v : float = Input.GetAxis (“Vertical”);
var moveDir : Vector3 = Vector3 (h, v, 0);
moveDir *= Time.deltaTime * speed;
transform.Translate (moveDir);