How can i put a simple loader to show the image download progress. Heres the script. Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class LoadWWW : MonoBehaviour { public RawImage img; public string url = "http://nfx3d.000webhostapp.com/ii.png"; void Start (){ StartCoroutine (LoadImageToUnity ()); } public IEnumerator LoadImageToUnity() { WWW W = new WWW (url); yield return W; Texture2D te = W.texture; img.texture = te; }}
Instead of just yielding on your www object with one yield statement, you can make a busy loop like so: Code (csharp): while( !W.isDone) { fractionComplete = W.progress; yield return null; } And then use that fractionComplete (a float from 0 to 1) to display a loading bar, etc. Actually, come to think of it you might just be able to access the W.progress value outside of your downloading coroutine but I usually like to marshal it out like the above. Plus, technically the WWW object implements the IDisposable interface so you should always use it within a using() block, or be sure to .Dispose it after completion. An example of a using() block can be found at the main docs page: https://docs.unity3d.com/ScriptReference/WWW.html