- Home /
What is the best way to modify the Car Tutorial for more cars?
I've done some extensive work on the Car Tutorial, making my own levels, checking for whether on the road, adding a speedometer and tachometer. Now I want to change the car.
I was thinking I could just load a different .fbx at runtime and change the stats on the car for suspension and acceleration, etc. To that end, I was thinking of storing all the information for all of the cars in an XML file, and basically selecting a car from the list of cars in the xml file.
Three questions:
Is that the best way to handle this?
I've noticed that the car is not just a single fbx, and that I'd need to load my fbx, and set a texture/material. Is there any direction/tutorials on loading and skinning a car (that can be used with the tutorial) at runtime?
Does Unity offer native support for reading/writing XML files or will I need to write my own class?
Sounds fine
Sorry, no clue
Yes if you consider System.IO and similar stuff "native"; there's plenty of doc/examples on X$$anonymous$$L to get you started (but you'll need to write your own basic class)
Answer by Jiro-Ng · Mar 31, 2014 at 04:18 AM
1. I'm not sure about it but i don't think this will work.
2. Create a prefab for each car model. You can set all those material, acceleration, etc to prefab. During runtime, you just need to instantiate the selected car prefab.
3. http://unitynoobs.blogspot.com/2011/02/xml-loading-data-from-xml-file.html (c#) http://answers.unity3d.com/questions/155868/how-load-xml-file-in-java.html (java)
Seems like this makes sense. Are all the prefabs in the hierarchy, or just in the Assets folder?
In the assets folder, you doesn't need to drag them to the hierarchy, but need to pass to the script that instantiate the prefab
@Jiro: I've been trying to figure out how to do this. I've made a copy of the car prefab. I can't modify the variables (acceleration, etc) because both prefabs use the same script, and changing it for one changes it for all. $$anonymous$$aybe I'd be better off making a single prefab for a car, and loading/setting it's variables (mesh, skin, acceleration) from datafiles?
Yes you can. You can use the same script in different cars. Are you changing the variable in the inspector?
Answer by Tanoshimi2000 · Apr 23, 2014 at 12:21 PM
I figured you could change the inspector variables and that would not affect the script directly. It was just those variables that were not public (in the inspector), and also the way the code handled certain things that I would need to change. Last night I bought a package of cars, and started modifying the scripts to work with them instead. Since they're all built identically, once I modify the script, I can use it with any of them.
Your answer
Follow this Question
Related Questions
How to load a large number of fbx files in runtime(files from Navisworks) 0 Answers
Export objects to a .3DS file at runtime 1 Answer
Set up Maya/FBX file so that it is automatically assigned an existing material on import? 2 Answers
Textures not in-tact in FBX import 3 Answers
Setting Avatar to Humanoid at runtime 0 Answers