Thursday, August 7, 2014

UNITY: Key press & one step movement control

Vector3 pos;

void Start () {
}

void Update () {

float veloc = 0.1f;

if(Input.GetKeyDown(KeyCode.LeftArrow))
{
pos = new Vector3(veloc * -1,0,0);
}
else if(Input.GetKeyDown(KeyCode.RightArrow))
{
pos = new Vector3(veloc,0,0);
}
else if(Input.GetKeyDown(KeyCode.UpArrow))
{
pos = new Vector3(0,veloc,0);
}
else if(Input.GetKeyDown (KeyCode.DownArrow))
{
pos = new Vector3(0,veloc * -1,0);
}

transform.localPosition += pos;
pos = new Vector3(0,0,0);
}