I am essentially trying to create a subway surfers game for a project. So the plane is divided into three tracks. Left, Middle, Right. If the player is at right, I want to move the player to the middle position and if the player is in the middle, the player has to move to the extreme left position, when pressed “a”.
But when I press A, the player initially in the rightmost position(-2,0,0) goes directly to (2,0,0) (left) instead of middle(0,0,0). This is because the update function works very fast and hence press “a” satisfies both conditions. Any solutions?
if(Input.GetKey("a")){
Vector3 p = transform.position;
if(p.x==0){
Debug.Log("Moved to 2");
transform.position = new Vector3(2, 0, p.z);
}
if(p.x==-2)
{
Debug.Log("Moved to 0");
transform.position = new Vector3(0, 0, p.z);
}
}