-2
\$\begingroup\$

I only got one scene to load when the timer reaches zero; I need one more scene to load. The scene manager builder index is not working for me. I have tried Application.Load() and SceneManager.Load(), but nothing works.

I can only reload the other scene with the following line of code, but it reloads the current scene, and I don't want it to do that.

SceneManager.LoadScene(SceneManager.GetActiveScene().name);

The scene I am trying to reload is my restart. It's suppose to load the scene I have set up in the build settings. It's also suppose to load when the timer reaches a set time, and does that, but only with the previous line of code.

Here is the rest of my code:

using UnityEngine; 
using System.Collections; 
using UnityEngine.UI; 
using UnityEngine.SceneManagement;

public class TestScript : MonoBehaviour 
{ 
    public MyClockScript myClock; 
    public ScoreManagerScript scoremanager; 
    public int scoreToReach = 99; // change this value to what you want 
    public string nextScene = "FY"; // change this value to what you want

    void Update () 
     {
       if (myClock.m_leftTime <= 0)
       {
         if ((ScoreManagerScript.score >= scoreToReach) && (nextScene != ""))
         {
           SceneManager.LoadScene(nextScene);
         }
         else
         {
           int gy = SceneManager.GetActiveScene().buildIndex;
         }
       }
     }
 }

Help would be appreciated. I have a picture of what I scene I want to load, too.

My build settings screen. The desired scene, scene "GY" or 2, is highlighted.

\$\endgroup\$
  • \$\begingroup\$ If you provide the project to a user, who is able to find problems but reports "Even with the code as it is, I am able to load scenes FY and GY", the exact problem you were reporting in the first place, it is clear that you are not providing a clear sample that demonstrates the problem you are reporting. "Questions about debugging a problem must provide a minimal, complete, verifiable example of the issue so that readers can diagnose it without needing to guess, read all of your code, or engage in extensive back-and-forth dialog.". \$\endgroup\$ – Gnemlock Aug 15 '16 at 23:00
1
\$\begingroup\$

This code works fine. The only issue is at the bottom, where you have another LoadScene() which uses the index 2. Even with the code as it is, I am able to load scenes "FY" and "GY".

void Update ()
{
    if (myClock.m_leftTime <= 0) 
    {       //checking if there is a next scene
        if ((ScoreManagerScript.score >= scoreToReach) &&
            (SceneManager.GetActiveScene ().buildIndex + 1 < 
                                   SceneManager.sceneCountInBuildSettings)) 
        {
            //load scene with next scene index
            SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex + 1);
            // SceneManager.LoadScene (nextScene);
            Debug.Log ("We are inside next scene if");
        } 
        else 
        {
            //load scene with current scene index/general reload
            SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex);
        }

        //load scene with next scene index
        SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex + 2);
        // Because this last load scene doesn't have a condition statement,
        // the script loads index 1, and than index 2. 
    }
}

Unrelated issue with enemies

Also, when running the game ,there was an out-of-range on your EnemiesSpawner.cs. I fixed it by doing the below;

for (int spawnCount = 0; spawnCount > 20; spawnCount++)
{
            Instantiate (enemy, spawnPoints [spawnPointIndex].position,
                                                   spawnPoints [spawnPointIndex].rotation);
}

In addition, you might want to randomize how the enemies are spawned, as every time I started the game they spawn at the same location. Game looks great, by the way! Good luck.

\$\endgroup\$
  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$ – Josh Aug 15 '16 at 4:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.