tungi
tungi

Reputation: 15

Threading in unity

On button click I run method Initialize().

private IEnumerator Initialize()
{
    Download download;
    download = new Download();

    StartCoroutine(download.LoadAsset("http://localhost/3dobjects?key=11","car13",(x)=>{j = x;}));
    yield return j;

    int k=download.GetRate(j)    
}

Second one (GetRate) depends on result from first method (LoadAsset), so it should run after LoadAsset finishes working.

But they run synchronously like in different thread, how to solve it?

Upvotes: 0

Views: 228

Answers (1)

Andy J Buchanan
Andy J Buchanan

Reputation: 1950

I think you want to

yield return StartCoroutine( ...

otherwise you won't be waiting for the coroutine to end.

Upvotes: 1

Related Questions