-
Incorporate Progress Bar in Unity3D
about 11 years ago
-
about 11 years ago
It's really difficult to implement progress bar in Unity!! So,Thank you so much for this :)
-
about 11 years ago
How to make a progress bar in Unity3D Game
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.
Example:
- var small:GUISkin;
- private var loadingArea:Rect;
- private var barDisplay : float = 0;
- private var pos:Rect;
- private var size : Vector2;
- var emptyProgressBar : Texture2D;
- var fullProgressBar : Texture2D;
- var progress : Texture2D;
- var simpleskin:GUISkin;
- function Start()
- {
- loadingArea = Rect(0,0,Screen.width,Screen.height);
- skin = small;
- txtPos = Rect(380,180,273,81);
- pos = Rect((Screen.width/2)-200,270,520,65);
- size = Vector2(400,75);
- StartCoroutine(LoadALevel(levelName));
- }
- public IEnumerator LoadALevel(string levelName)
- {
- async = Application.LoadLevelAsync(levelName);
- yield return async;
- }
- void OnGUI()
- {
- if (async != null)
- {
- barDisplay = float.Parse(async.progress.ToString());
- GUI.BeginGroup (loadingArea);
- GUI.skin = skin;
- GUI.Box(loadingArea,"");
- GUI.Label(txtPos,text);
- GUI.EndGroup();
- GUI.BeginGroup (pos);
- GUI.skin = simpleskin;
- GUI.Box (new Rect (0,0, size.x, size.y),emptyProgressBar);
- GUI.BeginGroup (new Rect (0, 0, size.x * barDisplay, size.y));
- GUI.Box (new Rect (0,0, size.x, size.y),fullProgressBar);
- GUI.EndGroup ();
- GUI.EndGroup ();
- }
- }
var small:GUISkin; private var loadingArea:Rect; private var barDisplay : float = 0; private var pos:Rect; private var size : Vector2; var emptyProgressBar : Texture2D; var fullProgressBar : Texture2D; var progress : Texture2D; var simpleskin:GUISkin; function Start() { loadingArea = Rect(0,0,Screen.width,Screen.height); skin = small; txtPos = Rect(380,180,273,81); pos = Rect((Screen.width/2)-200,270,520,65); size = Vector2(400,75); StartCoroutine(LoadALevel(levelName)); } public IEnumerator LoadALevel(string levelName) { async = Application.LoadLevelAsync(levelName); yield return async; } void OnGUI() { if (async != null) { barDisplay = float.Parse(async.progress.ToString()); GUI.BeginGroup (loadingArea); GUI.skin = skin; GUI.Box(loadingArea,""); GUI.Label(txtPos,text); GUI.EndGroup(); GUI.BeginGroup (pos); GUI.skin = simpleskin; GUI.Box (new Rect (0,0, size.x, size.y),emptyProgressBar); GUI.BeginGroup (new Rect (0, 0, size.x * barDisplay, size.y)); GUI.Box (new Rect (0,0, size.x, size.y),fullProgressBar); GUI.EndGroup (); GUI.EndGroup (); } }
The above example will help you create a progress bar that will show progress of loading the desired scene.
Happy Coding......
about 11 years ago
It's really difficult to implement progress bar in Unity!! So,Thank you so much for this :)
1 Comment(s)