- Home /
Question by
justadeveloper · Nov 27, 2015 at 11:15 AM ·
coroutineasyncloading screenasynchronous
How to load scene when async.progress is 0.9?
I want to load my scene when async.progress is 0.9,but first of all,i want to run my loading screen text at least once,but i dont know why it doesnt work
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class LoadScreenScript : MonoBehaviour
{
public Text DoYouKnow;
public Text loadingText;
public int imageNumber;
public float letterPause;
public string sceneToLoad;
string messageToAnimate;
// Use this for initialization
void Start ()
{
messageToAnimate = ".......";
loadingText.text = "Loading";
changeDoYouKnowText ();
StartCoroutine (LoadingScreen ());
}
// Update is called once per frame
void Update ()
{
}
void changeDoYouKnowText()
{
imageNumber = Random.Range (1, 5);
Debug.Log (imageNumber);
if (imageNumber == 1)
DoYouKnow.text = "hello mikel";
else if (imageNumber == 2)
DoYouKnow.text = "hello erick";
else if (imageNumber == 3)
DoYouKnow.text = "hello kevin";
else if (imageNumber == 4)
DoYouKnow.text = "hello world";
}
IEnumerator LoadingScreen ()
{
AsyncOperation async = Application.LoadLevelAsync (sceneToLoad);
Debug.Log(async.progress);
async.allowSceneActivation = false;
do{
foreach (char letter in messageToAnimate.ToCharArray())
{
loadingText.text += letter;
yield return 0;
yield return new WaitForSeconds (letterPause);
}
loadingText.text = "Loading";
Debug.Log(async.progress);
}while(async.progress<0.9);
async.allowSceneActivation = true;
}
}
Comment
Your answer
Follow this Question
Related Questions
How to make functions async? 2 Answers
StartCoroutine and Yield 0 Answers
Async parse.com query not working on Android/iOS 2 Answers
LoadLevelAsync movie not playing gui!! 1 Answer
Unity interthread communication. 1 Answer