Hi I created an XML file containing the data of 3 fruits. I imported the XML file in Assets/Scripts folder now I am trying to connect to it and retrieve the data using the following code. I followed this example
http://wiki.unity3d.com/index.php?title=Saving_and_Loading_Data:_XmlSerializer
public class FruitObj : MonoBehaviour {
[XmlAttribute("name")]
public string Name;
public int Sugar;
public decimal Protein;
}
[XmlRoot("FruitCollection")]
public class FruitContainer
{
[XmlArray("Fruits")]
[XmlArrayItem("Fruit")]
public List Monsters = new List();
public static FruitContainer Load(string path)
{
var serializer = new XmlSerializer(typeof(FruitContainer));
using (var stream = new FileStream(path, FileMode.Open))
{
return serializer.Deserialize(stream) as FruitContainer;
}
}
//Loads the xml directly from the given string. Useful in combination with www.text.
public static FruitContainer LoadFromText(string text)
{
var serializer = new XmlSerializer(typeof(FruitContainer));
return serializer.Deserialize(new StringReader(text)) as FruitContainer;
}
}
and I am trying to connect in my gameobject using
public class AppleNutritionalFacts : MonoBehaviour
{
void Start()
{
var fruitCollection = FruitContainer.Load(Path.Combine(Application.streamingAssetsPath, "NutrionArXML.xml"));
}
}
Then I am getting this error![alt text][1]
[1]: /storage/temp/51219-error.png
Can anyone please tell me what im doing wrong?
↧