- Home /
Unity will not switch scenes.
Hello! I am trying to make a simple game where the player picks up a sword and shield, then goes through a door which switches to the next scene. My only issue is that the sword and shield are bound to the FPS camera, and I do not want to have those prefabs become destroyed when I switch to a different scene. I tried DoNotDestroyOnLoad for the FPS camera, (since the sword and shield are children of the FPS camera/are root objects) But when I tried to hit the button that would allow me to switch scenes, it did not. It instead kept me in the same scene, which then got, for some reason, much brighter. I set up a debug.log for when the game switched scenes, but it returned back even though the scene did not change. Here is the code that switches the scene- `
public class DoorUI : MonoBehaviour {
public GameObject Wording;
public GameObject Sword;
public GameObject Shield;
public GameObject text2;
public GameObject Square;
public bool rara;
public GameObject FPS;
// Use this for initialization
void Start () {
Wording.SetActive(false);//UI for an objective
}
// Update is called once per frame
void Update () {
if(rara == true)
{
text2.SetActive(false);
Square.SetActive(false);
}
}
private void OnMouseOver()
{
if (Input.GetKeyDown(KeyCode.E) && Sword.activeInHierarchy && Shield.activeInHierarchy)
{ SceneManager.LoadScene("SimpleSword2part2", LoadSceneMode.Additive);
DontDestroyOnLoad(this.FPS);
rara = true;
}
Wording.SetActive(true);
}
private void OnMouseExit()
{
Wording.SetActive(false);
}
}
Any help would be greatly appreciated!
Answer by Drewtooroo · May 18, 2018 at 01:01 AM
If you want the current scene to disappear and the new scene to appear, then you should use "LoadSceneMode.Single" like:
SceneManager.LoadScene("SimpleSword2part2", LoadSceneMode.Single);
"LoadSceneMode.Additive" will load the new scene without unloading the existing scene.
I believe you will also need to call "DontDestroyOnLoad" before loading the next scene:
DontDestroyOnLoad(this.FPS);
SceneManager.LoadScene("SimpleSword2part2", LoadSceneMode.Additive);
Your answer

Follow this Question
Related Questions
NetworkManager.ServerChangeScene from client to server 0 Answers
Change Scene by Drag 0 Answers
how to switch scene on trigger in unity photon 0 Answers