I am making a car game and I would like to have a Car selection screen in my first scene, and then load an instantiated prefab from the selection in the next scene. So how I understand this process is that essentially I need the player to press a button for selection his/her car which then sends a message to the next scene to instantiate a certain prefab.
Does anyone know how to set up a script like this? Any help would be highly appreciated!
you needs to take an for loop for all car button. suppose you have 5 car . put all car info in an arrayList.
public string[] cararray=new string[5];
void Start ()
{
cararray[0]=car1;
cararray[1]=car2;
cararray[2]=car3;
cararray[3]=car4;
cararray[4]=car5;
}
foreach(int i=0;i<=5;i++)
{
if(GUILayout.Button(""+cararray[i],GUILayout.ExpandWidth(true)))
{
carname=cararray[i];
// use any function to call this car here
}
}
Many thanks to both of you for the replies and the excellent code from achingupta87!
Ravel: so I will need to bring it with me to the next scene? Interesting… So I could have a show room of 5 cars, if I choose one, then I set a DontDestroyOnLoad on the car chosen and Destroy the others right?
Or I guess it could be solved with adding code to the button that Instantiates the Prefab in the menu scene and adding a DontDestroyOnLoad to that Prefab.