Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Code1345 · May 17, 2018 at 11:32 PM · unity 5scene-switching

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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);
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Code1345 · May 19, 2018 at 12:48 AM 0
Share

Thank you! This worked perfectly.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

168 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

How to use NetworkManager.ServerChangeScene ? 1 Answer

Can any body tell me why this happens, Scenes from bundles crashes only on ios (iphone 7 plus) and only when i try to unload them or change the scene from a bundle scene to a normal scene? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges