I’m trying to make a thing where first the opening plays, which is the cracking and the portal opening, then the loading for the main menu which is the portal spinning, then when the loading finishes the portal plays 1 final animation and then it sends you to the next scene that has been loading during the portal spin animation.
However
I can’t figure out a way to make it so that the portals final animations plays only after the loading finishes and then you go to the next scene AFTER its done. I tried it and it doesn’t work. I already know why but I ran out of ideas of what to do.
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
public class OpeningScene : MonoBehaviour
{
public GameObject Crack1;
public GameObject Crack1Particle;
public GameObject Crack2;
public GameObject Crack2Particle;
public GameObject Crack3;
public GameObject Portal;
public GameObject PortalParticle;
public Animator myAnimator;
public string levelToLoad;
private bool loadingEnded = false;
private bool openingEnded = false;
private void Start()
{
StartCoroutine(Opening());
}
private void Update()
{
if (loadingEnded)
{
StartCoroutine(FinishedLoadingAnim());
}
}
IEnumerator Opening()
{
yield return new WaitForSeconds(3f);
Crack1.SetActive(true);
yield return new WaitForSeconds(3f);
Crack1Particle.SetActive(false);
Crack2.SetActive(true);
yield return new WaitForSeconds(3f);
Crack2Particle.SetActive(false);
Crack3.SetActive(true);
yield return new WaitForSeconds(3f);
Crack1.SetActive(false);
Crack2.SetActive(false);
Crack3.SetActive(false);
Portal.SetActive(true);
PortalParticle.SetActive(true);
myAnimator.SetBool("Opened", true);
yield return new WaitForSeconds(5f);
PortalParticle.SetActive(false);
// Opening cutscene finished.
Debug.Log("Opening finished!!!");
openingEnded = true;
}
IEnumerator LoadLevelASync(string levelToLoad)
{
// Load the next scene.
AsyncOperation loadOperation = SceneManager.LoadSceneAsync(levelToLoad);
// Wait for the scene to finish loading.
while (!loadOperation.isDone)
{
yield return null;
}
}
IEnumerator FinishedLoadingAnim()
{
Debug.Log("Loading finished!!!");
myAnimator.SetBool("LoadingDone", true);
yield return new WaitForSeconds(3f);
}
}