I made coroutine which will do my loading in game but every time i click play button I get NullReferenceException on line: StartCoroutine(LoadNewScene());
Here is my full code:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Loading : MonoBehaviour
{
private bool LoadScene = false;
[SerializeField]
private int scene = 0;
[SerializeField]
private Text LoadingText;
[SerializeField]
private Text TipText;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
if (LoadScene == true)
{
scene++;
}
}
public void Load()
{
LoadScene = true;
//LoadingText.color = new Color(LoadingText.color.r, LoadingText.color.g, LoadingText.color.b, Mathf.PingPong(Time.time, 1));
StartCoroutine(LoadNewScene()); //here is my error
}
IEnumerator LoadNewScene() // my coroutine
{
yield return new WaitForSeconds(3);
AsyncOperation async = SceneManager.LoadSceneAsync(scene);
while (!async.isDone)
{
yield return null;
}
}
}