Reading file for input

Hello, are there any input commands for reading text from a file?

Thanks,
~Thordis

You just use .NET classes for that (System.IO namespace). Googling for something like “C# file reading” reveals lots of tutorials as well.

Reading and writing files is disabled in the web player for security reasons.

Someone here shared these links:

Read text:

Write text:

This may or may not be useful but is what I used for some testing purposes and and XML.

import System;
import System.IO;
import System.Xml;

function Start(){

	var xmlFile = Application.dataPath + "/test.xml";
	
	if (File.Exists(xmlFile)){
		
		
		var sr = new StreamReader(xmlFile);
		var txt = sr.ReadToEnd();
		
		var xml = new XmlDocument();
		xml.LoadXml(txt);
		
		Debug.Log(xml.FirstChild.ChildNodes.Count);
		
		for (var i=0;i<xml.FirstChild.ChildNodes.Count;i++){
			Debug.Log(xml.FirstChild.ChildNodes[i].NodeType + "  " + xml.FirstChild.ChildNodes[i].OuterXml + "  " + xml.FirstChild.ChildNodes[i].Attributes.Count);
		}
	}
}

And here is the XML I used for a sample:

<test>
    <some>
        <someInfo att='someText'>And Some Crap</someInfo>
    </some>

    <another someAtt='anAtt'>
        <someInfo>And Some Crap</someInfo>
    </another>

    <onemore>
        <someInfo att='someText'>And Some Crap</someInfo>
    </onemore>
</test>

HTH someone.

– Clint

Ah great, thank to both of you, I now have the objects in my game all being placed via a ‘map file’.

Thanks!
~Thordis

Would you mind sharing a little more information on how you did this? Thanks!