Vehicle selection screen

I’m trying to wrap my head around setting up a selection screen for vehicles. So I’ve been doing my research and so far I believe I have to create an array to store a series of vehicles. I need the game to remember the vehicle that’s been chosen and spawn that vehicle in any world the user chooses. I really don’t know how to full on tackle this technically, but I am finding research that helps here and there. If anyone can give me a small boost with a start, and I can take the whole way (as a learning experience). If anyone would like to help I can offer the compensation of (30) free models or I can model and texture and single asset (low poly) you might need. My selection screen will be in the main menu…it will have 4 basic vehicles on the one screen, a user would be able to click on a vehicle and it will do a turnaround (which I can create my own animations for) and then basically they can return to main menu screen and launch into a level. Ideally their selected vehicle will be the one that spawns at the starting line in any track they choose. If I didn’t mention I need help in scripting this functionality.

Hi, here’s how I’d do it:

In any game I make which uses levels, I tend to make an empty GameObject called “theBrain” which sits on Level0 and has the following script attached so it will persist across all the subsequent levels:

function Awake () {
    DontDestroyOnLoad (this);
}

I use “theBrain” script to also hold any recalled data from memory, high scores, playerNames, etc.

Then, once you have loaded any memory data etc. - just advance to Level1 (Main Menu), here you can choose to go to your car selection screen, etc.

In your selection screen, when the user clicks on a car they want to pick, they could actually just be clicking an invisible GUI button, and when they do so, the button they clicked tells a variable in theBrain’s script which car was selected (1,2,3 or 4).

Now, whenever you move to any track levels, you can easily just ask theBrain which car prefab to instantiate.

Hope that makes sense?

Here’s a few code snippets which might help (untested, simplified for illustration):

(Sure you can use an Array to hold the prefabs, but the below code does not go into that)…

LEVEL 0

// Brain Script (must be called BrainScript)

// A variable to remember which car the player chose:
var selectedPlayerCar : int;

function Awake () {
    DontDestroyOnLoad (this);
}

Level 1

// Car Selection Script

// Link to the Brain Script:
private var theBrain : BrainScript;

function Awake(){
    // Complete the reference to the Brain Script:
    theBrain = FindObjectOfType(BrainScript);
}

function OnGUI () {
    // Button 1 to choose Car 1
    if (GUI.Button (Rect (0, 0, 100, 20), "CAR1")){
        // Spin Car 1
        
        // Tell the Brain which car was chosen
        theBrain.selectedPlayerCar = 1;

        // Go back to Main Menu
    }

    // Button 2 to choose Car 1
    if (GUI.Button (Rect (0, 100, 100, 20), "CAR2")){
        // Spin Car 2
        
        // Tell the Brain which car was chosen
        theBrain.selectedPlayerCar = 2;

        // Go back to Main Menu
    }

    // etc.

}

Level 2

// Racing Track Script

// Link to the Brain Script:
private var theBrain : BrainScript;

function Awake(){
    // Complete the reference to the Brain Script:
    theBrain = FindObjectOfType(BrainScript);
}

function Start(){
    
     if (theBrain.selectedPlayerCar == 1 ){
        
        // Instantiate Car 1

    }

     if (theBrain.selectedPlayerCar == 2 ){
        
        // Instantiate Car 2

    }

}

Hey, I’m not saying this is the only way to do this, but it’s the easiest to explain! :razz:

I can help. Ill send an example project of what I use when I finish my homework…
I dont really use and array to select them. It takes a little longer to set up but it works.

Edit: oh we posted at the same time. Hey James if you still want it tell me, but RobbieDingo’s is pretty similar

James,

You’ll need some good-looking UI to present the cars, probably in a spinner or line-up of cars where the “active” car is scaled up a little more than the others, a la Crusin USA or some other coin-op racing game. You’ll need to track what is the active car and store is once the user has made a selection… Then, you’ll need to be able to access that car throughout the game, within other levels, etc. So the selected car needs to be stored rather permanently.

I would use static variables in my “CarSelection” scripts so that the selected car can be accessed by (and potentially changed by) any other script. So, after the car is selected, you could write (and yeah, this is pseudocode…):

CarSelection.selectedCar = <the car the user selected. selectedCar is a GameObject>;

later, when you want to Instantiate said car in some other script - say, level 1, you would call that car like this:

Instantiate (CarSelection.selectedCar, Vector3.zero, Quaternion.identity);

Hope this helps.

I actually have a working menu, (here’s a vid of it in action - http://www.youtube.com/watch?v=1leWU2VWSgM&feature=channel_video_title ) just need to place in my (4) vehicle objects and some menu behaviors on them…I’m just to the point of creating the part where a user actually touches on a vehicle and it selects and stores it for the user…ideally when then select a track to race it would start with their selected vehicle. I wanted to initially create it to where a user could swap to a more customized texture on their vehicle, but the scripting aspect is holding me back on that aspect as well right now. All of the help in this thread is amazing…cannot believe how awesome you all are to help me. I most definitely must pay back this forum in any way I can help. I’m also thinking giving free versions of my final game to folks who have helped me in it’s creation :slight_smile:

Cheers James.

To do a texture swap, just have an array of the materials (assigned in the inspector) and do the same thing as I suggested above - ie. use the brain to remember the integer which will point to the position in the array.

Good luck!

R

I learned to do character selection from the Unity Tutorial by the same title. Techniques ought to be similar to vehicle selection with texture swaps.

Gypsy - Where did you see the Unity Character Select tutorial by chance?

:wink:

Sweet baby Jesus…this should definitely set me on the right path. Thanks Earl, thanks everyone!

*Actually I’ve looked this over and I think it’s getting ahead of me a bit…I still need to establish a screen with 4 vehicles to choose from, selecting one and then the game remembering my vehicle and loading it into whatever level I choose to play. I’m still gnawing away at all these things. I need like an idiot’s guide for real lol.

I actually found a free project for Unity 3.0 called CarEdu that might actually have everything I need in it…it’s like a car racing game tutorial project with main menu functionality in it as well…thought I’d share if anyone else needed a resource like this.

Please share that tutorial because i am also stuck at the same problems from selecting the vehicle …

How can I do it to Prefabs(Cars)?