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 ();
}
}
The above example will help you create a progress bar that will show progress of loading the desired scene.
Happy Coding......
1 Comment(s)