- Home /
how to create xml file and read xml file in C# ? Unity
I need a function to create a xml file so i can produce my cardgame data to xml and I need a function to load a xml file to read my cardeffect.xml and able to access it using another gameObject.
my cardeffect.xml
<catalog>
<deckregion name="Phoenix">
<card no="1">
<type name="Action Card">
<name>Burning Waves</name>
<effect>500 damage to target</effect>
<costMP>300</costMP>
</type>
</card>
</deckregion>
</catalog>
I need some help to read this xml using C# , and how i able to load it into variable that i need?
I try the code and attached to game object , after that i create SaveData.xml to assets folder but when i run it display this error warning The class defined in script file named 'SaveData.xml'does not match the file name!
Answer by TonyLi · Dec 09, 2013 at 05:19 PM
Follow this tutorial: http://wiki.unity3d.com/index.php?title=Saving_and_Loading_Data:_XmlSerializer
Or Microsoft's: http://msdn.microsoft.com/en-us/library/182eeyhh%28v=vs.110%29.aspx
In brief:
Add your XML file to the project. It will be a TextAsset.
Define a class with a [System.Serialized] tag at the top.
Use XmlSerializer.Deserialize (as shown in the bottom of this page) to read the XML TextAsset into an instance of the class.
We can point you in the right direction, but unityAnswers isn't the place to ask for someone to write code for you. If you want to hire someone to write the code for you, you can post in the Commercial: Job Offering forum.
Answer by zombience · Dec 09, 2013 at 05:11 PM
Check into the load/save package that is on the unifycommunity, it is written in C# (and JS) and can help you understand what you might need to do. It should provide a framework for everything you're trying to do, and is modifiable in case you need more.
Answer by zzeeshann · May 26, 2016 at 07:46 PM
Check out this video tutorial
i have gotten this far, but i am struggling to assign the data from the list to variables inside a class.
Your answer
Follow this Question
Related Questions
Read AND Write to XML at runtime 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers