How can I move a character in a cube-like movement that moves 1 unit when you hold w a s or d?
I have done:
function Start () {
for(var n : int; n==0;n=0) {
move.x = Input.GetAxisRaw("Horizontal");
move.y = Input.GetAxisRaw("Vertical");
while(move == Vector3.zero) {
move.x = Input.GetAxisRaw("Horizontal");
move.y = Input.GetAxisRaw("Vertical");
yield;
}
if(move.x > 0 && !Physics.Linecast(transform.position,transform.position+Vector3(1,0,0)))
transform.Translate(1,0,0);
else if(move.x < 0 && !Physics.Linecast(transform.position,transform.position+Vector3(-1,0,0)))
transform.Translate(-1,0,0);
if(move.y > 0 && !Physics.Linecast(transform.position,transform.position+Vector3(0,1,0)))
transform.Translate(0,1,0);
else if(move.y < 0 && !Physics.Linecast(transform.position,transform.position+Vector3(0,-1,0)))
transform.Translate(0,-1,0);
yield WaitForSeconds(1f/moveSpeed);
}
}
But I was wondering if there was another method I could do this, that doesn’t require for loops… (I have this for a 2D game using the X and Y axis)