Hello, I have created a coroutine for
asynchronous scene loading with moving DontDestroyOnLoad object, but there is a problem when I try to load the scene that was
loaded, it doesn’t load the correct scene, but LoadScene does.
private System.Collections.IEnumerator Load(int sceneBuildIndex)
{
GetComponent<AudioSource>().Play();
var leaves = transform.GetChild(0).GetComponent<RectTransform>();
if (!disableAnim)
while (leaves.anchoredPosition.y > -180)
{
leaves.anchoredPosition += Vector2.down * animSpeed * 100 * Time.deltaTime;
yield return null;
}
var sceneLoad = SceneManager.LoadSceneAsync(sceneBuildIndex, LoadSceneMode.Single);
while (!sceneLoad.isDone)
yield return null;
if (!disableAnim)
while (leaves.anchoredPosition.y < 1260)
{
leaves.anchoredPosition += Vector2.up * animSpeed * 100 * Time.deltaTime;
yield return null;
}
}