Hi,
i need to fill a array with a for loop for each item in an xml file.
Within in the forloop by the first line it’s says “use of unassigned local variable items”
I tried everything and cannot find a solution.
Anyways here the code:
public Item[] loadXmlFile(string filename,string tagname)
{
Item[] items;
TextAsset file;
file = Resources.Load(filename) as TextAsset;
XmlDocument xmlFile = new XmlDocument();
xmlFile.LoadXml(file.text);
XmlNodeList listNodes = xmlFile.GetElementsByTagName(tagname);
for (int i = 0; i <= listNodes.Count; i++)
{
items_.itemName = listNodes*.Attributes["itemname"].Value;*_
items_.prefab = (Transform)Resources.Load(listNodes*.Attributes[“prefab”].Value);
items.icon = (Texture2D)Resources.Load(listNodes.Attributes[“icon”].Value);
items.buildCost = listNodes.Attributes[“buildcost”].Value;
items.maxInhab = listNodes.Attributes[“maxInhab”].Value;
items.elecConsump = listNodes.Attributes[“elecconsump”].Value;
items.waterConsump = listNodes.Attributes[“waterconsump”].Value;
items.xpAdd = listNodes.Attributes[“xpadd”].Value;
items.itemText = listNodes.Attributes[“itemtext”].Value;
}
return items;
}*_