- Home /
Question by
SomeSortOfHuman · Aug 01, 2013 at 09:09 PM ·
wwwyieldwhile
How can I have a while(www is loading) loop?
I have a
var googlePage : WWW = WWW("http://www.google.com/");
and the code to wait until is loaded and then do stuff
yield googlePage;
Debug.Log("Done!");
I have a cube (It's a circular loading bar), and I want to use a while loop to change the texture (frame) every 0.5 seconds. Something like
var frames : Texture2D[]
function LoadGoogle(){
var googlePage : WWW = WWW("http://www.google.com/");
while(yield googlePage){
//From http://wiki.unity3d.com/index.php?title=Texture_swap_animator
var index : int = Time.time * 0.5; //0.5 are the frames per second
index = index % frames.Length;
renderer.material.mainTexture = frames[index];
}
Debug.Log("Done!");
}
Comment
how about:
while (!googlePage) {
/*Stuff*/
yield;
}
index = index % frames.Length;
is fine. Adding 1 would just make it skip frame 0 for the first run-though; not sure why you'd do that.
Best Answer
Answer by Eric5h5 · Aug 02, 2013 at 12:26 AM
while (!googlePage.isDone) {
// stuff
yield;
}
If it's any consolation, I had this open in a tab for a while and didn't even see your commment. ;) I like that we both had "stuff" as a comment....
I also like how we had the same basic idea too XD
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
How to set timer for WWW helper? 1 Answer
Issue with yield 0 Answers
Save Unfinished Download 0 Answers