Hello! I’m trying to start a coroutine in a static void which is in a non-instantiated script. Once i try to call the void I get a NullReferenceException at line 12. Can anyone help me solve this issue?
Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using Game.Effects;
public class SceneLoader : MonoBehaviour
{
public static void LoadSceneByName(string sceneName, float fadeOutLength = 0f, float fadeInLength = 0f)
{
MonoBehaviour mono = new MonoBehaviour();
mono.StartCoroutine(LoadScene_Num(SceneManager.GetSceneByName(sceneName).buildIndex, fadeOutLength, fadeInLength));
}
static IEnumerator LoadScene_Num(int sceneIndex, float fadeOutLength, float fadeInLength)
{
Effects.DoFade(fadeOutLength, FadeType.FadeOut);
yield return new WaitForSeconds(fadeOutLength);
AsyncOperation operation = SceneManager.LoadSceneAsync(sceneIndex);
yield return operation.isDone;
Effects.DoFade(fadeInLength, FadeType.FadeIn);
}
}