- Home /
How do I return scene using bulid index scenemanager in c#
I am having a problem is when timer reaches zero it reloads the current scene. I want to reload a different scene . I tried application load , scene manager load scene and nothing happens. Here is what I got for code :
else
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
}
}
What's the name of the scene you're trying to load? This code that you've posted does indeed just reload the current scene.
When going into FILE>BUILD_SETTINGS , check which scene you want to load. You should see a number next to a scene. Use that number in application.LoadLevel(TheSceneNumberHere); I know you said you tried it but i'm not sure if you enabled the scene too. $$anonymous$$ake sure that checkbox is ticked. If you haven't added the scene to the list already, open your desired scene and click the "Add open scenes" button in the BuildSettings window.
Answer by Jessespike · Aug 15, 2016 at 01:59 PM
To load the next scene in the build index, you can add "+1" after the current buildIndex:
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
It can be stored as an int, if you wish:
int nextBuildIndex = SceneManager.GetActiveScene().buildIndex + 1;
SceneManager.LoadScene(nextBuildIndex);
If a specific scene needs to be loaded, then it needs to be specified:
//examples
SceneManager.LoadScene("NameOfNewScene");
SceneManager.LoadScene(3);
I tried Scene$$anonymous$$anager.LoadScene("NameOfNewScene");
Scene$$anonymous$$anager.LoadScene(3); they didn't work .
Here is what I got for code now :
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.Scene$$anonymous$$anagement;
public class TestScript : $$anonymous$$onoBehaviour
{
public $$anonymous$$yClockScript myClock;
public Score$$anonymous$$anagerScript 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 ((Score$$anonymous$$anagerScript.score >= scoreToReach) &&
(Scene$$anonymous$$anager.GetActiveScene().buildIndex + 1 < Scene$$anonymous$$anager.sceneCountInBuildSettings))//checking if there is a next scene
{
Scene$$anonymous$$anager.LoadScene(Scene$$anonymous$$anager.GetActiveScene().buildIndex + 1);//load scene with next scene index
}
else
{
Scene$$anonymous$$anager.LoadScene(Scene$$anonymous$$anager.GetActiveScene().buildIndex);//load scene with current scene index/general reload
}
Scene$$anonymous$$anager.LoadScene(Scene$$anonymous$$anager.GetActiveScene().buildIndex + 2);//load scene with next scene index
}
}
}
Answer by maurogsw · Jul 24, 2019 at 07:44 PM
I have a Problem two , so i use binary files to save evrything but i save the int currentLevel and set that equal to the current buildindex so now i want to load with SceneManager currentLevel.
Any solutions?
Thanks