Skip to main content

Posts

Showing posts from October, 2014

How to Read and Write xml in unity Iphone and Android

Hi, So here is a working solution for guys who want to save there data in xml files for all platforms.

Things you should know, First time when you will run the game, there will be no xml present in the directory. So first thing you need to do is save the xml with default values. now you have a xml file where you can save and load data.

what i am doing here is , i have 4 players, i am setting there position randomly , saving there data and than loading there data from xml.

In this function getPath() you can see for Android and Iphone i am using  Application.persistentDataPath instead of Application.dataPath that's because in Iphone and Android you have permission to write files in Application.persistentDataPath only.



Here is the script

usingUnityEngine;
usingSystem.Collections;
usingSystem.Collections.Generic;
usingSystem.Xml;
usingSystem.Text;
usingSystem.IO;

publicclassGameManager : MonoBehaviour {

privateList<GameObject> Players = newList<GameObject>();
privatestringpath;
publicst…