The input string has the wrong format?

Gets this error when clicking on the F button, which should upload a save from an xml file in the game

FormatException: Input string was not in a correct format.
System.Number.ParseSingle (System.String value, System.Globalization.NumberStyles options, System.Globalization.NumberFormatInfo numfmt) (at :0)
System.Single.Parse (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) (at :0)
System.Single.Parse (System.String s) (at :0)
GameHelper.GenerateScene (System.Xml.Linq.XElement root) (at Assets/GameHelper.cs:56)
GameHelper.Load () (at Assets/GameHelper.cs:50)
GameHelper.Update () (at Assets/GameHelper.cs:18)


Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Xml.Linq;
using System.IO;
public class GameHelper : MonoBehaviour
{
 private string path;

 public List<SaveableObject> objects = new List<SaveableObject>();
 private void Awake()
{
 path = Application.persistentDataPath + "/textsave.xml";
}
 private void Update()
{
 if (Input.GetButtonDown("Jump")) { Save(); }
 if (Input.GetKeyDown(KeyCode.F)) { Load(); }
}
 public void Save() {

 XElement root = new XElement("root");
 foreach(SaveableObject obj in objects)
{
root.Add(obj.GetElement());

}
Debug.Log(root);
 root.AddFirst(new XElement("score", Data.score));
 SaveDoc XDocument = new XDocument(root);
 File.WriteAllText(path, saveDoc.ToString());
Debug.Log(path);
}
 public void Load() {
 Debug.Log("LOADING IS COMPLETE");
 XElement root = null;

 if (!File.Exists(path))
{
 if (File.Exists(Application.persistentDataPath + "/settings.xml"))
 root = XDocument.Parse(File.ReadAllText(Application.persistentDataPath + "/settings.xml")).Element("root");
}
 else {
 root = XDocument.Parse(File.ReadAllText(path)).Element("root");
}
 if (root == null) {
 Debug.Log("Level load failed");
return;
}
GenerateScene(root);
}
 private void GenerateScene(XElement root) {
 foreach (XElement instance is in root.Elements("instance"))
{
 Vector3 position = Vector3.zero;
 position.x = float.Parse(instance.Attribute("x").Value);
 position.y = float.Parse(instance.Attribute("y").Value);
 position.z = float.Parse(instance.Attribute("z").Value);

 Instantiate(Resources.Load<GameObject>(instance.Value), position, Quaternion.identity);
}
}
}
March 25th 20 at 13:39
0 answer

Find more questions by tags Visual StudioUnity Game EngineC#