i have 2 scenes in my game
i wish to make a progress bar in first scene according to waiting time to load second scene.
How can i do it with progrss bar.
Is anty other method with image to do it?
i have 2 scenes in my game
i wish to make a progress bar in first scene according to waiting time to load second scene.
How can i do it with progrss bar.
Is anty other method with image to do it?
Calling LoadLevelAsync like TheDarkVoid suggested will start the loading process. You could put it in a coroutine so other parts of the game can keep running. It returns an AsyncOperation. You can check ‘isDone’ to see if it’s done, or ‘progress’ to get the progress (0-1). Note that progress doesn’t work well in the editor, but is more accurate in builds.
Then you need to display the progress. Using Unity GUI, you can draw two textures: one for the empty bar background, and one for the filled progress.
public Texture2D emptyProgressBar; // Set this in inspector.
public Texture2D fullProgressBar; // 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(Rect(0, 0, 100, 50), emptyProgressBar);
GUI.DrawTexture(Rect(0, 0, 100 * async.progress, 50), fullProgressBar);
}
}
Take a look at LoadLevelAsync, it allows you to load a level and still have other stuff going on like a loading screen. It requires unity pro though, as far as i’m aware there’s no way to archive this without pro.
void OnGUI() { if (async != null) { GUI.DrawTexture(Rect(0, 0, 100, 50), emptyProgressBar); GUI.DrawTexture(Rect(0, 0, 100 * async.progress, 50), fullProgressBar); GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUI.Label(Rect(0, 0, 100, 50), string.Format("{0:N0}%", async.progress * 100f)); } } Please read: http://docs.unity3d.com/Documentation/Components/GUIScriptingGuide.html
– TonyLiWhen I tried this, the IEnumerator had to be a generic function outside the call to loading: private void SyncLoadLevel(string levelName) { async = Application.LoadLevelAsync (levelName); Load (); } IEnumerator Load () { yield return async; }
– LoungeKattHilarious.
– NeverTrustShadows