scene transition coroutine
Hello I am very new to Unity and have probably done something very simple wrong.
I have a scene transition to play between each scene when a scene change button is clicked, there's multiple scenes so I have two scripts going at the moment. One for the intro scene as I want a video logo to play and then scene change transition to play and then the other is in the game manager for all the other scene changers when both parts are needed in each scene. The intro scene one uses a different animator as otherwise the scene would open with the exit transition animation playing which I didn't want.
I have two issues, the first is in the entry scene in that the end transition plays automatically and doesn't wait first for the logo video to end. I think I must be doing something wrong with coroutines and wait time?
This is the script I am using:
public class IntroScene : MonoBehaviour { public float waitTime = 6f; // time of intro scenes public float transitionTime = 2f; //time of transition public Animator transition;
void Start()
{
StartCoroutine(introWait());
}
IEnumerator introWait() // allows logo video to play first
{
//video plays automically so coroutine has to wait before going
yield return new WaitForSeconds(waitTime);
transition.GetComponent<Animator>().SetTrigger("IntroStart"); //play scene transtion
yield return new WaitForSeconds(transitionTime); //wait time for transition to play
SceneManager.LoadScene("00_Start"); // moves into second scene
}
The second is with the game manager script and that Unity wants to load a scene called GameManager which doesn't exist as I thought I was using string values that I could chose which scene each button would take someone to from the inspector. I have the transition as a game object separate to the gamemanager prefab and it seems to play at the correct times but does not take to the right scene afterwards. This is the script I am using:
public class GameManager : MonoBehaviour { public static GameManager _instance;
public float transitionTime = 1f; //time of transition
public GameObject transition;
void Awake()
{
DontDestroyOnLoad(gameObject);
if (_instance != null) //if the gameobject is and it isn't this one
Destroy(this.gameObject); //destroy self (deletes temporary game managers in other scenes)
else
{
_instance = this;
}
Debug.Log(_instance);
}
public void LoadScene(string name)
{
StartCoroutine(SceneChange()); //start coroutine
}
IEnumerator SceneChange() // sets transition to play and then change scene to string
{
transition.GetComponent<Animator>().SetTrigger("Start"); //play scene transition
yield return new WaitForSeconds(transitionTime); //wait time for transition to play
SceneManager.LoadScene(name); //change scene to string name
}
public void Quit() //quits application
{
Debug.Log("Application Quit");
Application.Quit();
}
}
Very appreciative to any and all help!
Your answer
![](https://koobas.hobune.stream/wayback/20220613040543im_/https://answers.unity.com/themes/thub/images/avi.jpg)