How I can load and return file from another method(use WWW)?
I want to do next:
- Method
GetSettings(). Download file text, parse json and return result. - Call method from
Start()and wait whileGetSettings()return result.
How I can do this?
How I can load and return file from another method(use WWW)?
I want to do next:
GetSettings(). Download file text, parse json and
return result.Start() and wait while GetSettings() return result.How I can do this?
Looks like you want to downloaded data then wait then wait for the download to finish then download another data. If this is true the you can the code below will download data 2 times. You can increase the number of times by increasing the REQ_AMOUNT value.
It uses yield return StartCoroutine to wait for the current coroutine function to return before running again.
IEnumerator Start()
{
int REQ_AMOUNT = 2;
for (int i = 0; i < REQ_AMOUNT; i++)
{
yield return StartCoroutine(GetSettings());
}
}
IEnumerator GetSettings()
{
string url = RoomSettings.AbsoluteFilenamePath;
if (Application.isEditor)
{
url = "file:///" + url;
}
var www = new WWW(url);
yield return www;
// Do some code, when file loaded
}