I am trying to make a fade to another scene in unity when I came across a problem. For some reason when the coroutine begins the Ienumerator it only runs half of the Ienumerator Method which is only the anim.SetForBlue line. Heres my code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Loseforcube1 : MonoBehaviour
{
public GameObject blueWinPanel;
public Animator animForBlue;
// Use this for initialization
void Start()
{
blueWinPanel = GameObject.Find("Blue win panel");
animForBlue = blueWinPanel.GetComponent<Animator>();
}
public IEnumerator WaitTillNextScene()
{
animForBlue.SetTrigger("FadeBlueWin");
yield return new WaitForSeconds(3.9f);
SceneManager.LoadScene(2);
}
void OnTriggerExit()
{
if (GameObject.Find("Cube Player 2"))
{
StartCoroutine(WaitTillNextScene());
}
}
}