Quick newb question. I have an object in my scene with this simple code applied to it to move left and right:
function Update () {
if (Input.GetKey(KeyCode.A)){
transform.Translate(Vector3(1*Time.deltaTime*speed,0,0));
}else{
if (Input.GetKey(KeyCode.D)){
transform.Translate(Vector3(1*Time.deltaTime*speed,0,0));
}
}
my question is, how do I have it so that if I press A, the gameObject will position itself 2 unit to the right and then start translating? I'm guessing I can use transform.position.x+=2, but how do I implement this so it'll work inside the code? Thanks