- Home /
Question by
laruesteven · Nov 24, 2011 at 09:36 PM ·
sizeloadlevelscenesrace
New Game Object Same Scene
Hi I was trying to find out how to use the same scene for multiple game objects
I am making a race game for my nephew for Christmas and being some what new to Unity
and my limited skill level I am very pleased with where I am at on my first game.
But my question is how can I reuse the same track with different cars. The way my
game is set up right now or the only way I can do it at this point with my experience
is to create a game scene for every car on every track. The scene is called from the
main menu scene by first select car then Application.LoadLevel(""); brings up the
select track scene then Application.LoadLevel(""); brings up what ever car/track
was selected. The game has 9 car models and 5 tracks so that would be 45 individual
scenes which with duplication is not hard but would cause my game file to be very large.
So I was wondering if there is a more efficient way to build the game structure.
Comment
Answer by brumdogpro · Nov 24, 2011 at 10:30 PM
What I recommend doing is adding an empty gameobject and attaching a script called MasterSettings. Then make sure you add:
DontDestroyOnLoad(this.gameObject);
to the start function. This will keep it alive during scene switching.
Just use this script to store what car is selected and what track is selected. Once the level is loaded use something like this:
if(Application.loadedLevelName == "YourLevel") {
Instantiate(selectedCar, new Vector3("Insert Position"), Quaternion.identity);
Instantiate(selectedTrack, new Vector3("Insert Position"), Quaternion.identity);
}
Hope this works. If it doesn't just reply back and I will do my best to help out if needed.
Your answer
![](https://koobas.hobune.stream/wayback/20220613053140im_/https://answers.unity.com/themes/thub/images/avi.jpg)