How to do it...

To create XML text data through serialization, perform the following steps:

  1. Create a C# PlayerScore script class:
    using System.Xml.Serialization;     [System.Serializable]     public class PlayerScore     {         [XmlElement("Name")]         public string name;         [XmlElement("Score")]         public int score;         [XmlElement("Version")]         public string version;     } 
  1. Create a C# PlayerScoreCollection scrip class: 
    using System.Xml.Serialization;     using System.IO;     [XmlRoot("PlayerScoreCollection")]     public class PlayerScoreCollection     {         [XmlArray("PlayerScores"), XmlArrayItem("PlayerScore")]         public PlayerScore[] playerScores;         public void Save(string path) {             var serializer = new XmlSerializer(typeof(PlayerScoreCollection)); using (var stream = new FileStream(path, ...

Get Unity 2018 Cookbook - Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.