- Home /
Loading Xml file issues
Have a script that should load my Xml files but it doesn't seem to be working. This is my first time working with Xml and it probably a simple fix but I'm not sure exactly what the issue is. OnSpeedPress is connected to a button and when pressing that button Title.text is displayed as 0 and 1 is shown in the console, despite how many times I press the button. I also plan on running this on android so if there is an android specific issue I should know about please let me know. I should also mention that an Xml file is being created but I don't think I'm referencing the Speedlvl properly. Here's the save script:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
public class UpgradeSave : MonoBehaviour
{
public static UpgradeSave ins;
private void Awake()
{
ins = this;
}
public UpgradeDataBase UpgradeDB;
public void Save()
{
XmlSerializer serializer = new XmlSerializer(typeof(UpgradeDataBase));
FileStream stream = new FileStream(Application.dataPath + "/playerData.xml", FileMode.Create);
serializer.Serialize(stream, UpgradeDB);
stream.Close();
}
public void Load()
{
XmlSerializer serializer = new XmlSerializer(typeof(UpgradeDataBase));
FileStream stream = new FileStream(Application.dataPath + "/playerData.xml", FileMode.Open);
UpgradeDB = serializer.Deserialize(stream) as UpgradeDataBase;
stream.Close();
}
}
[System.Serializable]
public class UpgradeEntry
{
public int Manalvl;
public int Speedlvl;
public int Healthlvl;
public int Defenderlvl;
public int Bal;
}
[System.Serializable]
public class UpgradeDataBase
{
[XmlArray("UpgradeLevels")]
public List<UpgradeEntry> list = new List<UpgradeEntry>();
}
The script for the button
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UpgradeFunctions : MonoBehaviour
{
public Text Title;
public Text Description;
public Text Balance;
public Text PurchaseSuccesful;
public int price;
public Button Purchase;
public Text PurchaseTxt;
public void OnSpeedPress()
{
UpgradeEntry upgradeEntry = new UpgradeEntry();
Title.text = "" + upgradeEntry.Speedlvl;
upgradeEntry.Speedlvl++;
Debug.Log("" + upgradeEntry.Speedlvl);
UpgradeSave.ins.Save();
}
}
Your answer
Follow this Question
Related Questions
Save and Load data from Local XML file won't work 1 Answer
how can i deserialize xml to vector4 List?? 0 Answers
Distribute terrain in zones 3 Answers
xml parsing error 0 Answers