- Home /
Creating 3D levels with text and XML files
I am making a 3D platforming game.
I am currently creating levels in the Unity editor, but also allowing users to select text files from a folder and load them in. The text files are read to create 2.5D levels with all platforms / objects at the same height. I could vary the heights of objects by increasing the size of the key for the text file (as in p for platform, hp for higher platform etc) but this is messy and complicated.
I was thinking of how I could go about associating objects in the scene that have been loaded from the text file with data stored in an xml file to somehow describe how to position objects.
Has anyone done something like this has suggestions? Or perhaps there is a better alternative route to take? Thanks in advance for any assistance you provide. If you wish to know more about what I'm doing, just ask.
Edit: @daybson.paisante this is less a question of the literal process of loading xml, but rather how I would go about linking the retrieved value to the objects in the scene to create a 3D world. Hopefully that makes it clearer as to what I would like to achieve.
Answer by Bunny83 · Aug 13, 2014 at 01:24 PM
There are multiple ways of how to map "string based data" to GameObjects / prefabs.
Just create an array which holds all available prefabs. In your XML data you can simply use an index number to select which part you want to use.
Create an Dictionary based on the array approach of point 1 so each part can have a human readable name. The dictionary will help you mapping a part-name-string to an actual prefab
Use the resources folder to manage your prefabs. You can simply use the string you got from your XML data and use it with Resources.Load to get the desired prefab
The XML data can hold additional information such as an offset, orientation, color, ... or even more complex information such as links between a door and a lever. However that depends on what your level is made of.
The latter is essentially what I want to do. I want to link buttons with platforms. I have buttons in my scenes which change the colour of platforms when pressed. I can easily link a button to all platforms, but now I want to link them to specific platforms.