How to do something while yield is loading?

Hi i am trying to make something like a loader with this javascript code

var loaded = false;
while(loaded == false) {
    message += 1;
    yield  yieldTarget;
    loaded = true;
 }

But it doesent seem to work, any ideas?

Thanks

More people will read your question if you format your code. Select your code and use the 101/010 button. I formatted your code for you this time.

From now on i will do that i dident know abou it. Sorry!!!

Ok i am trying to make a loading bar while an asset (instantianted) is being loaded, because its for a web player, and the asset is 4 mb, and i have alot of them that the user has to load. Its something like a product gallery. I figured out that the web player wanted the yield command to work propertly. So i want a loading bar to appear while the yield(download) is beiing executed. The object loads just fine, but while it loads, i want to make a loading bar instead of the empty screen, so the user know that he has to wait.

You really need to post a new, clear question "How do I do a loading bar". Explain clearly it is for the web, etc etc etc don't mention yield etc. as it is irrelevant. Nobody will answer this question now, you know. I hope it helps !

1 Answer

1

You need to start a seperate coroutine if you want to execute different code that spans over time simultaneously in the same class. So:

var progress:float = 0;
var isLoaded:boolean = false;

function Start(){

   StartCoroutine(ProgressBar());
   //Do some code here that runs simultaneously
}

function ProgressBar(){

     progress = 0;

     while (progress < 100){

         progress ++;
         yield;
     }

     isLoaded = true;

}