public float FirstLanePos, // 1.5
LaneDistance, // -1.5
SideSpeed; // 5
float speed = 5;
int laneNumber = 1;
int lanesCount = 2; // лінії 0, 1, 2
bool didChangeLastFrame = false;
void Update()
{
float input = Input.GetAxis("Horizontal");
if (Mathf.Abs(input) > 0.1f)
{
if (!didChangeLastFrame)
{
didChangeLastFrame = true;
laneNumber += (int)Mathf.Sign(input);
laneNumber = Mathf.Clamp(laneNumber, 0, lanesCount);
}
}
else {
didChangeLastFrame = false;
}
Vector3 newPos = transform.position;
newPos.z = Mathf.Lerp(newPos.z, FirstLanePos + (laneNumber * LaneDistance), Time.deltaTime * SideSpeed);
transform.position = newPos;
}