Hey guys!
I just updated Unity and tried to play game in editor but it gives me this error: NullReferenceException: Object reference not set to an instance of an object
UILoadScreen.Update () (at Assets/Scripts/MainMenu/UILoadScreen.cs:24)
I’ve tried to fix this but no luck.
Scripts:
UILoadScreen
using UnityEngine;
using UnityEngine.UI;
public class UILoadScreen : MonoBehaviour {
public GameObject loadScreen;
public Slider loadingBar;
public Text loadPercent;
public float percentage;
LoadNewScene scene;
void Start () {
scene = FindObjectOfType<LoadNewScene> ();
}
void Update () {
if (scene.loading) {
loadScreen.SetActive (true);
}
loadingBar.value = scene.aSync.progress;
percentage = scene.aSync.progress / loadingBar.maxValue * 100;
loadPercent.text = percentage.ToString ("F0") + "%";
if (scene.aSync.isDone) {
loadScreen.SetActive (false);
}
}
}
LoadNewScene
using UnityEngine;
using UnityEngine.SceneManagement;
public class LoadNewScene : MonoBehaviour {
public string sceneName;
public AsyncOperation aSync;
[HideInInspector]
public bool loading;
public void LoadScene () {
aSync = SceneManager.LoadSceneAsync (sceneName);
loading = true;
}
}
Can someone help? ![]()