I am running in to an error that states a CoRoutine couldnt be started because the Object "Script Loader’ is ‘Inactive’. I don’t know what this means.
I am trying us a CoRoutine to increment my stages based on the current scene, but only if that scene = to index scene 4 or higher…
public class SceneLoader : MonoBehaviour
{
int currentScene;
[Range(1, 10)] [SerializeField] float loadTime = 5;
LevelMusic levelMusic;
AudioSource audioSource;
// Start is called before the first frame update
void Start()
{
currentScene = SceneManager.GetActiveScene().buildIndex;
if (currentScene == 0)
{
StartCoroutine(LoadMainMenu());
}
else if (currentScene <= 1)
{
Debug.Log("Current Scene is: '" + SceneManager.GetActiveScene().name + "' .");
//Tells me what scene I am on, if I don't activate the game
//from the Splash Screen.
}
}
//Scene Navigation
public void LoadContinue()
{
//Checks to see If the current screen's index number is Lower then 4,
//if it is, returns the player to the Realm Select Screen.
//(this allows Game Over Screen Continue Button to Function as intended,
//for the moment.) For any scene index above 4, Load (increment the scene)
//to the next Level.
currentScene = SceneManager.GetActiveScene().buildIndex;
if (currentScene >= 4 )
{
StartCoroutine(LoadNextLevel());
}
else { SceneManager.LoadScene("3. RealmSelect"); }
}
public void LoadRealmSelect() { SceneManager.LoadScene("3. RealmSelect"); }
public void LoadGameOver() { SceneManager.LoadScene("1. GameOver"); }
//Realm Select Navigation
public void LoadW1L1() { SceneManager.LoadScene("Level1-1"); }
public void LoadW2L1() { SceneManager.LoadScene("Level2-1"); }
public void LoadW3L1() { SceneManager.LoadScene("Level3-1"); }
public void LoadW4L1() { SceneManager.LoadScene("Level4-1"); }
public void LoadW5L1() { SceneManager.LoadScene("Level5-1"); }
public void LoadW6L1() { SceneManager.LoadScene("Level6-1"); }
//Coroutines
//loads the StartScreen
IEnumerator LoadMainMenu()
{
yield return StartCoroutine(BeginMusic());
yield return new WaitForSeconds(loadTime);
SceneManager.LoadScene("2. MainMenu");
}
//Begins LevelMusic scripting
IEnumerator BeginMusic()
{
FindObjectOfType<GameObject>();
Debug.Log("The Object is" + FindObjectOfType<GameObject>().name + ".");
audioSource = gameObject.GetComponent<AudioSource>();
audioSource.volume = .10f;
audioSource.Play();
yield return new WaitForSeconds(0);
}
//Increments current scene
IEnumerator LoadNextLevel()
{
currentScene = currentScene++;
yield return new WaitForSeconds(0);
}
}