- Home /
Loading Bar Help
Hi!
I would like to get some help with my loading bar. I want to slow it down so you really can see that it's loading. Now it pops up for like 1 second then dissapears. I know it depends on how heavy your scene is but is there any other way to slow it down?
The script:
var ProgressBar : GameObject;
var Text : GameObject;
var Backgraund : GameObject;
var LevelToLoad : String;
private var loadProgress : int = 0;
function Start ()
{
Backgraund.SetActive(false);
Text.SetActive(false);
ProgressBar.SetActive(false);
}
function Update ()
{
if(Input.GetKeyDown("space"))
{
StartCoroutine("DisplayLoadingScreen");
}
}
function DisplayLoadingScreen(): IEnumerator
{
Backgraund.SetActive(true);
Text.SetActive(true);
ProgressBar.SetActive(true);
ProgressBar.transform.localScale = new Vector3(loadProgress,ProgressBar.transform.localScale.y, ProgressBar.transform.localScale.z);
Text.guiText.text= "Loading..." + loadProgress + "%";
var async : AsyncOperation = Application.LoadLevelAsync (LevelToLoad);
while(!async.isDone)
{
loadProgress = async.progress * 100;
Text.guiText.text = "Loading..." + loadProgress + "%";
ProgressBar.transform.localScale = new Vector3(async.progress,ProgressBar.transform.localScale.y, ProgressBar.transform.localScale.z);
return;
}
}
Looks to me like while(!async.isDone) is blocking until it's completed. Try return new WaitForEndOfFrame() ins$$anonymous$$d of return;
I get an error "Cannot convert 'UnityEngine.waitForEndFrame' to 'System.Collections.IEnumerator'"
I used "yield" ins$$anonymous$$d of "return new" and it it takes a little bit lobger to load. But it still loads to random number, like 76. I want to see it load up to 100 then the level can load
yeah sorry, i use C# so I'm not sure the java syntax. If you want it to actually get to 100 then make it wait another frame after async.isDone