- Home /
Question by
benfattino · Oct 05, 2015 at 06:21 PM ·
coroutinewww
Wait load scene until finish load menu
I have this script to load Sprite for menu. How can do unity wait until all sprite are loaded before start scene?
...
public vois Awake (){
StartCoroutine (LoadIconArray (ModelGrid , "_n"));
Manager.ModelSpriteNormal = SpriteArr;
}
...
...
IEnumerator LoadIconArray (string [,] grid, string suffix){
SpriteArr = new Sprite [grid.GetUpperBound (1)];
for (h = 0; h < grid.GetUpperBound (1); h++) {
string url = Manager.IconModelUrl + grid [1, h] + suffix + ".png";
Manager.url2 = url;
WWW www = new WWW (url);
yield return www;
if (!string.IsNullOrEmpty (www.error)) {
Debug.Log (www.error);
yield return www;
}
Tex2D = www.texture;
Sprite Sprt = Sprite.Create (Manager.Tex2D, new Rect (0, 0, Manager.Tex2D.width, Manager.Tex2D.height), new Vector2 (0.5f, 0.5f));
SpriteArr [h] = Sprt;
}
}
...
Comment
Answer by vfxjex · Nov 22, 2016 at 12:26 AM
you can use the async operation
AsyncOperation asyncLoadLevel;
IEnumerator LoadLevel (){
asyncLoadLevel = SceneManager.LoadSceneAsync("MyLevel", LoadSceneMode.Single);
while (!asyncLoadLevel.isDone){
print("Loading the Scene");
yield return null;
}
}
Your answer
Follow this Question
Related Questions
Using a method to get the string from a download. 3 Answers
Avoid using MonoBehaviour just for StartCoroutine or WWW load 0 Answers
yield return request never returns 2 Answers
Yield Problems 2 Answers
Method returning data from WWW 1 Answer