Ok so basically I’ve been at this all day and no matter what I’ve tried I keep getting red warnings.
The below script (assembled from various forum posts) seems to work perfectly fine but I need
to get this to run on awake in a blank scene or a loading screen:
public class LoadingScreen : MonoBehaviour {
public Texture2D emptyProgressBar; // Set this in inspector.
public Texture2D fullProgressBar; // Set this in inspector.
public string LevelName; // Set this in inspector.
private AsyncOperation async = null; // When assigned, load is in progress.
private IEnumerator LoadALevel(string levelName)
{
async = Application.LoadLevelAsync(levelName);
yield return async;
}
void OnGUI()
{
if (async != null)
{
GUI.DrawTexture(new Rect(0, 0, 100, 50), emptyProgressBar);
GUI.DrawTexture(new Rect(0, 0, 100 * async.progress, 50), fullProgressBar);
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
GUI.Label(new Rect(0, 0, 100, 50), string.Format("{0:N0}%", async.progress * 100f));
}
}
}