- Home /
Progress Bar at Game StartUp
Good evening to all, I'm struggling with Unity to create a nice progression bar when the game starts that doesn't need any button to start loading.
I created an Empty Object called LoadingGame whose children are the background Image with its own Canvas and the Slider.
Then I created a new GameObject called LoadScript to which I assigned the following script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class LoadingScript : MonoBehaviour {
public GameObject LoadingScreenObj;
public Slider MySlider;
AsyncOperation async;
// Use this for initialization
void Start () {
StartCoroutine (LoadMyScreen ());
}
IEnumerator LoadMyScreen()
{
LoadingScreenObj.SetActive (true);
async = SceneManager.LoadSceneAsync (0);
async.allowSceneActivation = false;
while (async.isDone == false)
{
MySlider.value = async.progress;
if (async.progress == 0.9f)
{
MySlider.value = 1f;
async.allowSceneActivation = true;
}
yield return null;
}
}
// Update is called once per frame
void Update () {
}
}
I assigned the slider and the LoadingGame as references to the variables. I also defined the scene order in Build Settings.
The second scene is made by a plane and a "capsule" character free to move.
When I click play, the progress bar is permanently loading and reloading several times in a second.
How can I solve my problem? Here's a picture of my layout: [IMG]http://i68.tinypic.com/51q6bs.png[/IMG]
I would be really thankful to anyone answering me
Answer by Bilelmnasser · Sep 26, 2017 at 08:28 AM
there is No Problem in your script !! just try to change : if (async.progress == 0.9f)
to
if (async.progress >= 0.9f)
Answer by jaywulf · Sep 25, 2017 at 11:14 PM
Would be quite helpful if there as any answers here, im actually after the exact same thing right now. Anyone know?
Your answer
![](https://koobas.hobune.stream/wayback/20220612130123im_/https://answers.unity.com/themes/thub/images/avi.jpg)