The first question I have for now is: what is this "my file" string in
the line
That's supposed to be the name of the file.Although, it is missing it's extension name. You should add that. For example, .txt, .jpg, png....
What am I supposed to write there? Is it a url? And if it is a url,
the url of what?
You are just supposed to write the name of the file with the extension name where "MyFile" is.
Example uses:
In your Project, you create a folder called "StreamingAssets".
Let's say that you have a file named "Anne.txt", and the file is inside the "StreamingAssets". folder, this should be your path:
public string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "Anne.txt");
Now let's say that the "Anne.txt" folder is placed in a folder called "Data" which is then in the "StreamingAssets" folder, it should look like this: "StreamingAssets/Data/Anne.txt".
Your path should be:
public string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "Data");
filePath = System.IO.Path.Combine(filePath , "Anne.txt");
That's it. Nothing complicated here. You then use that path string with WWW
.
Also your if (filePath.Contains("://"))
should be if (filePath.Contains ("://") || filePath.Contains (":///"))
.
EDIT
If you have multiple files you want to load, I simplified that function into this so that it takes the file name as parameter.
IEnumerator loadStreamingAsset(string fileName)
{
string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, fileName);
string result;
if (filePath.Contains("://") || filePath.Contains(":///"))
{
WWW www = new WWW(filePath);
yield return www;
result = www.text;
}
else
result = System.IO.File.ReadAllText(filePath);
}
Now, let's say that you have 3 files called "Anne.txt", "AnotherAnne.txt" and "OtherAnne.txt" placed in the "StreamingAssets" folder, you can load them with the code below:
StartCoroutine(loadStreamingAsset("Anne.txt"));
StartCoroutine(loadStreamingAsset("AnotherAnne.txt"));
StartCoroutine(loadStreamingAsset("OtherAnne.txt"));