I created my fps microgame and connected the secondary scene with the main scene. When I win in the main scene it changes into the secondary scene but when I win in the secondary scene instead of going to the winning scene it again plays the secondary scene. I want it to go to the winning scene after winning in the secondary scene. Pls, help me with this.
Can you add your code so I can try to see the issue?
It would help with providing your code, but thinking about your problem I’m assuming you are calling the same code that loads the second scene.
So in some class, you may have something like:
public void loadSecondaryScene()
{
SceneManager.LoadScene("SecondaryScene");
}
You might be calling this again.
Instead you could have something like this:
using UnityEngine;
using UnityEngine.SceneManagement;
public class SceneLoadingManager : MonoBehaviour
{
private const string MAIN_SCENE = "MainScene";
private const string SECONDARY_SCENE = "secondaryScene";
public void loadNextScene()
{
if (SceneManager.GetActiveScene().name == MAIN_SCENE)
{
SceneManager.LoadScene(SECONDARY_SCENE);
}
else if (SceneManager.GetActiveScene().name == SECONDARY_SCENE)
{
SceneManager.LoadScene(MAIN_SCENE);
}
}
// OR THIS (better imo)
public void loadMainScene()
{
SceneManager.LoadScene(MAIN_SCENE);
}
public void loadSecondaryScene()
{
SceneManager.LoadScene(SECONDARY_SCENE);
}
}
Then in your mysterious code, you can do:
SceneLoadingManager.loadNextScene();
or this below approach (which is better in my opinion since its much more obvious in your code what is going to happen):
SceneLoadingManager.loadMainScene();
SceneLoadingManager.loadSecondaryScene();