So I have a very basic racing game, where I would like the car to stop once it hits the finish line. Respectively when the distance between the car and the finish line hits or goes under 0 the car stops, but instead of stopping it continues to go on. How can I fix this?
Here's my code:
public float speed = 0f;
public float gravity = 0f;
public Transform finishline;
public Transform car;
public Transform finish;
void CarMove ()
{
if (Vector2.Distance (finishline.position, car.position) != 0)
{
if ( Input.GetKey(KeyCode.RightArrow))
{
transform.Translate(Vector2.right * speed * Time.deltaTime);
}
else
{
return;
}
}
}
// Update is called once per frame
void Update ()
{
CarMove();
}
}