Using arrow buttons to go through objects. How?

Hello, How would i make it so that i can use arrows to go through objects? the only problem is if your going back, it doesn’t know which car was last.

Like the arrows on the bottom. Any ideas?

How are you accessing your cars?

If its in an array, its actually quite simple.

public GameObject[] cars = new GameObject[0];
public GameObject curCarObj;

private int curCar=0;

void OnGUI () {
    if (GUILayout.Button ("Left Arrow")) {
        PreviousCar ();
    }

    if (GUILayout.Button ("Right Arrow")) {
        NextCar ();
    }
}

void PreviousCar () {
    curCar--;
    if (curCar < 0)
        curCar = cars.Length-1;

    Destroy (curCarObj);
    curCarObj = Instantiate (cars[curCar]) as GameObject;
}

void NextCar () {
    curCar++;
    if (curCar > cars.Length-1)
        curCar=0;

    Destroy (curCarObj);
    curCarObj = Instantiate (cars[curCar]) as GameObject;
}

You could just put them all on a wheel, which rotates say 45 degrees when you click the button, which would mean that you cycle through all the different cars. They all just have to be the same point that they are rotating about.