select car in garage

how to do such a thing as I press the NEXT appears to me to be the next car http://img846.imageshack.us/i/garagee.jpg/ perhaps by changing the camera but I do not know how to do it:(

and how do I choose one of these cars that it appeared on a new scene

2 Answers

2

Hi,

If you only need to have a different car poping up and replace the current one, then you don't need to animate or do any camera mixing stuff.

Simply maintain a list of all the cars you want to be visible and maintain a variable that knows which car is currently visible. So if you have 4 car, the current car at start would be car 0.

the user press next or previous:

 1 hide the current car ( car x )
 2 select the next or previous car in your list ( car x +- 1 )
 3 show that one.

Does that make sense?

I have built a very basic c# component that will give you a starting point. Nothing fancy and 100% full proof, but the basic idea is here. If you have problems, let me know.

1: Simply create a c# script, and name it GOSelector. Edit it and paste the code below

2: drop it on any gameobject

3: select the component in the inspector

4: Define the number of items you want to have in GOList

5: drag and drop each one of them onto each items of GOList

6: optionnaly set a location for where you want them GameObject to be located.

Run. and press the left and right arrows to show the next or previous GameObject.

using UnityEngine;
using System.Collections;
public class GOSelector : MonoBehaviour {

    public GameObject[] GOList;
    private int _currentID;

    public Transform GOLocationSpot;

    // Use this for initialization
    void Start () {

        // if GOLocation spot is not declare, will use our own transform instead.
        if (GOLocationSpot== null){
            GOLocationSpot = transform;
        }
        // start by hiding all
        foreach(GameObject _go in GOList){
            // we move it to the right location
            _go.transform.position = GOLocationSpot.position;
            // and we hide it for now.
            _go.active = false;
        }

        // now show the first
        ShowID(0);
    }

    // Update is called once per frame
    void Update () {

            if (Input.GetKeyDown(KeyCode.RightArrow)){
                ShowNext();
            }

            if (Input.GetKeyDown(KeyCode.LeftArrow)){
                ShowPrevious();
            }
    }

    void ShowNext(){
        ShowID(_currentID+1);
    }

    void ShowPrevious(){
        ShowID(_currentID-1);
    }

    void ShowID(int ID){

        if (ID>=GOList.Length){
            ID = 0;
        }else if (ID<0){
            ID = GOList.Length;
        }

        // hide the current
        GOList[_currentID].active = false;

        // now store the new ID as being the current
        _currentID = ID;
        GOList[_currentID].active = true;

    }// ShowID
}

Hope it helps,

Bye,

Jean

Thanks for this great answer, but how can i use the selected car into another scene?

Prefab GameObject's can not be made active! (CAMARO) UnityEngine.GameObject:set_active(Boolean)????