- Home /
Creating part of the 2d level with a text file, part in editor?
I have a 2d game with tiles, which can load the tiles from a text file. The thing is I want to load the text file into the editor so I can play around with it, and add more things to the scene, based on the location of the tiles.
I am only using the text file as a faster way to place tiles (as I find with 2d, it takes a while to do)
Is there any way to get the editor to run a script to load objects off the text file?
Answer by Julien-Lynge · Jun 06, 2012 at 11:25 PM
The way you can access text files (both in the editor and in compiled games) is through a Resources folder - place your text file in a folder called 'Resources' under the Assets directory and Unity will load it.
http://unity3d.com/support/documentation/ScriptReference/Resources.Load.html
Then, if you know how to program, you can create an editor script that will place the tiles in the scene.
http://unity3d.com/support/documentation/Components/gui-ExtendingEditor
For instance, if you want the tiles to be placed when selecting a menu item:
http://unity3d.com/support/documentation/ScriptReference/MenuItem.html
If you have your tiles as prefabs, be sure to check out http://unity3d.com/support/documentation/ScriptReference/PrefabUtility.html for how to instantiate the prefabs in-scene.
BTW: The text file will become a TextAsset when Unity imports it. Here's how you work with TextAssets:
http://unity3d.com/support/documentation/Components/class-TextAsset.html
http://unity3d.com/support/documentation/ScriptReference/TextAsset
thank you for that well answered...answer! I have the tiles as prefabs, and the text file will let me know the location the tiles need to go. I will extend the editor to read and print the locations, then I will create scenes with foreground/background and save them in relation to each text file. Thanks! (i wanted to upvote, but it said i don't have permission)
Your answer
Follow this Question
Related Questions
World building advice for 3.5D platformer 0 Answers
Texturing rooms all the same? 1 Answer
Ways to texture very large mesh 0 Answers
How would you go about designing and implementing an indoor level? 2 Answers
Playing a Level-Up Sound 1 Answer