This question was
closed Nov 18, 2016 at 08:38 PM by
Jay1234 for the following reason:
The question is answered, right answer was accepted
Question by
Jay1234 · Nov 18, 2016 at 07:40 PM ·
loadingloading screenprogress-bar
I'm trying to create a progress loading bar and i keep getting the error message, "NullReferenceException: Object reference not set to an instance of an object". I'm kinda new to Unity, what am i doing wrong, am i missing something?
using UnityEngine; using System.Collections; using UnityEngine.SceneManagement; using UnityEngine.UI;
public class loadingBar : MonoBehaviour {
AsyncOperation ao;
public GameObject loadingScreenBG;
public GameObject loadingLogo;
public Image progBar;
public Text loadingText;
void Start()
{
StartCoroutine(loadmainScene());
StartCoroutine(LoadLevelwithRealProgress());
}
void Update()
{
}
IEnumerator loadmainScene()
{
loadingScreenBG.SetActive(true);
loadingLogo.SetActive(true);
yield return new WaitForSeconds(1);
progBar.gameObject.SetActive(true);
loadingText.gameObject.SetActive(true);
loadingText.text = "Loading. . .";
}
IEnumerator LoadLevelwithRealProgress()
{
yield return new WaitForSeconds(1);
ao = SceneManager.LoadSceneAsync(1);
ao.allowSceneActivation = true;
while(!ao.isDone)
{
progBar.fillAmount = ao.progress;
Debug.Log(ao.progress);
yield return null;
}
}
}
Comment
Best Answer
Answer by Jay1234 · Nov 18, 2016 at 08:37 PM
I figured it out, stupid me lol. I was asking it to load Scene 1 but i forgot to add Scene 1 in the build settings..... such a silly mistake lol..
Follow this Question
Related Questions
How to check is the game loaded in index.html? 1 Answer
Gear VR Loading screen freeze 0 Answers
Loading Bar For Each Canvas in a Scene 1 Answer
[ISSUE] Delay after splash screen 5 Answers