- Home /
Car Selectin Script
Hi ... I'm making a racing game for android and I have some problems with my Car Selection Script .
 **function CarList()
 {
 
 var currentCar : int = PlayerPrefs.GetInt("Quick Race Car");
 
 if (currentCar == 0){
  PlayerPrefs.SetInt("Quick Race Car", 2);
 }
 if (currentCar == 1){
  PlayerPrefs.SetInt("Quick Race Car", 2);
 }
 if (currentCar == 2){
  PlayerPrefs.SetString("Current Q Car", "Audi TT");
 }
 if (currentCar == 3){
  PlayerPrefs.SetString("Current Q Car", "Audi S6");
 }
 if (currentCar == 4){
  PlayerPrefs.SetString("Current Q Car", "BMW M3");
 }
 if (currentCar == 5){
  PlayerPrefs.SetString("Current Q Car", "Ford Mustang");
 }
 if (currentCar == 6){
  PlayerPrefs.SetInt("Quick Race Car", 5);
 }
 }**
This is the car list and the rest of code is this :
 function QuickRace()
 {
  GUILayout.BeginArea (new Rect (25, 12, Screen.width-50, Screen.height-24));
  GUILayout.Label("Select Car : " + PlayerPrefs.GetString("Current Q Car"));
  GUILayout.BeginHorizontal ();
 
  if (GUILayout.Button ("Previous"))
     {
         // go back to the main menu
         PlayerPrefs.SetInt("Quick Race Car", PlayerPrefs.GetInt("Quick Race Car") - 1);
         CarList();
 
     }
 
  if (GUILayout.Button ("Next"))
     {
         // go back to the main menu
         PlayerPrefs.SetInt("Quick Race Car", PlayerPrefs.GetInt("Quick Race Car") + 1);
         CarList();
 
     }
     GUILayout.EndHorizontal();
     
     var currentCar : int = PlayerPrefs.GetInt("Quick Race Car");
     
     // Select The Race Track that you want
     if (currentCar < 2){
  GUILayout.Label (AudiTT);
  }
     if (currentCar == 2){
  GUILayout.Label (AudiTT);
  }
  if (currentCar == 3){
  GUILayout.Label (AudiS6);
  }
  if (currentCar == 4){
  GUILayout.Label (BMWM3);
  }
  if (currentCar == 5){
  GUILayout.Label (FordMustang);
  }
  if (currentCar >= 6){
  GUILayout.Label (FordMustang);
  }
     
  GUILayout.BeginHorizontal ();
     if (GUILayout.Button ("Back"))
     {
         // go back to the main menu
         this.currentGUIMethod = MainMenu;
     }
     GUILayout.EndArea();
 }
but this code is in the main menu script and i want to make it more complex like to add a variable of max speed for example ... and this code don't work any more from when i have update unity to 3.5.5 ... so please help me to make it to optimize it ...
Use the switch case statement in java! $$anonymous$$akes it alot easier to read than tons of if statements. here is a tutorial: http://www.youtube.com/watch?v=Ynnh-3yg674
Answer by subcod · Aug 13, 2012 at 06:22 PM
USE THE SWITCH CASE STATEMENT IN JAVA TO SELECT THE CAR!
here is a tutorial: http://www.youtube.com/watch?v=Ynnh-3yg674
Your answer
 
 
             Follow this Question
Related Questions
How do I add bots in android? 2 Answers
Level Button And Quit Button Android 2 Answers
Error UCE0001 ";"Expected 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                