- Home /
scene loader issue
so I made a crossfade for transition between scenes, works perfectly for loading the opening scene but wont load the next scene (no errors but wont load)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelLoaderScript : MonoBehaviour
{
public Animator transition;
public float transitionTime = 1f;
void update()
{
// Press the space key to start coroutine
if (Input.GetKeyDown(KeyCode.Space))
{
LoadNextLevel();
}
}
public void LoadNextLevel()
{
StartCoroutine(LoadLevel(SceneManager.GetActiveScene().buildIndex + 1));
}
IEnumerator LoadLevel(int levelIndex)
{
transition.SetTrigger("Start");
yield return new WaitForSeconds(transitionTime);
SceneManager.LoadScene(levelIndex);
}
}
Have you added all scenes to the build list?
File->Build Settings->Scenes In Build
Try adding prints before and after every line to see where it stops. You can also use the debugger to step through the code line by line.
Debug.Log("test1");
...
Weird that you don't get an error. Have you checked the build list like rh_galaxy said? It should give you an error if you try to load a level that is outside of the buildindex. The scene wouldn't load if the Animator was set to null in the other scene. However, this should also give you a error.
The only issue I can think about that wont give you an error is if you have set the transitionTime to a high number in the other scene. Even though you set the transitionTime to 1 it could be different in the inspector. The value in the inspector will override your 1 so you might have just mistakenly written a high number.
I made sure the scenes in build in the right order, I have tried the change the time but no use it like it not resisting the spacebar comand