- Home /
Question by
manuelmangual · Feb 27, 2017 at 11:26 PM ·
c#unity 5coroutineloading
Issues with my loading screen
Problem: users want to see a visual feedback of the loading progress.
Solution: Display a percentage somewhere on the screen to display a visual feedback
Bug: My loading screen stays at 0% then it shows 90% and then it loads level 1.
Desired output: display 1%..2%...3% so on and so forth
Here is my code:
IEnumerator WaitForLevelToLoad(GameObject obj)
{
yield return new WaitForSeconds(0.001f);
Destroy(_startWindowInstance);
var instance = Instantiate(loadGamePrefab);
instance.transform.SetParent(transform, false);
yield return new WaitForSeconds(1f);
AsyncOperation level = SceneManager.LoadSceneAsync("Level1", LoadSceneMode.Single);
var percentage = 0f;
while (!level.isDone)
{
yield return null;
percentage = level.progress * 100f;
instance.transform.FindChild("PercentValue").GetComponent<Text>().text = percentage.ToString();
}
}
I call this coroutine in a function called OnButtonClicked()
Comment
Does it go quicker than it should to 90% or does it act as if it's freezing and moving while frozen, then unfreezing at 90?
Your answer
Follow this Question
Related Questions
How to delay gameobject from falling by time? 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Terminal-like GUI, wait for input 1 Answer