Why is my coroutine not working?
I am using code from this you tuber and he is using a canvas with a image to use as a something to fade to scenes i used everything from this video https://www.youtube.com/watch?v=C_Ok4xC_xVU&list=PLPV2KyIb3jR4u5jX8za5iU1cqnQPmbzG0∈dex=24 . It work for its first attempts so i got off then when i got back on it tell me Coroutine couldn't be started because the the game object 'SceneFader' is inactive! . every time i try to switch and now it wont switch scenes
here my code i got everything hook UP and reference using System.Collections; using UnityEngine.UI; using UnityEngine.SceneManagement; using UnityEngine;
public class SceneFader : MonoBehaviour {
public Image img;
public AnimationCurve curve;
void Start()
{
StartCoroutine(FadeIn());
}
public void FadeTo (string scene)
{
StartCoroutine(FadeOut(scene));
}
IEnumerator FadeIn()
{
float t = 1f;
while(t > 0f)
{
t -= Time.deltaTime;
float a = curve.Evaluate(t);
img.color = new Color (0f, 0f, 0f, a);
yield return 0;
}
}
IEnumerator FadeOut(string scene)
{
float t = 0f;
while (t < 1f)
{
t += Time.deltaTime;
float a = curve.Evaluate(t);
img.color = new Color(0f, 0f, 0f, a);
yield return 0;
}
SceneManager.LoadScene(scene);
}
}
Comment