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 KingKamal · Mar 06, 2018 at 06:53 PM · noobsceneslevelsroll a ballpls

Help with scene switching with a game object trigger.

I got a game object to act as a trigger to switch scenes after touching it it, the problem is that after the scene switches, the previous scene is still there and running, So when i move my player it ends up hitting the game object again creating another load of the scene. How do I go about this?? I heard i can destroy the object after but i dont know how to do so.

Comment
Add comment · Show 1
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 Laurence_B · Mar 06, 2018 at 07:10 PM 0
Share

Are your running two scenes simultaneously?

3 Replies

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

Answer by AlejandroBoss10 · Mar 07, 2018 at 05:54 PM

This is what I have for loading an entirely different scene. So you put a trigger on the object that is acting as the trigger. Attach this script. Type the name of the scene in the box in the inspector, be sure to check that the scene is spelled letter by letter and is in your build settings. Below is the script, checked and working. If you need more info, just say something.

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;

public class OnTriggerScene : MonoBehaviour {

 public string loadLevel;

 void OnTriggerEnter(Collider other)
 {
     SceneManager.LoadScene(loadLevel);
 }

}

Comment
Add comment · Show 3 · 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 KingKamal · Mar 07, 2018 at 06:31 PM 0
Share

it works better than what i had before, but when i load the next level the lighting is messed up. The scene darkens, as if it hasn't finished loading. Any fix for this?

avatar image dsabatier KingKamal · Mar 07, 2018 at 07:42 PM 0
Share

This is probably only an issue in the editor (You should make a build to confirm). To fix it in the editor in both of your scenes go to Window > Lighting > Lightmaps and disable auto and click bake. Both of your scenes :)

avatar image AlejandroBoss10 dsabatier · Mar 08, 2018 at 05:28 PM 0
Share

@dsabatier is absolutely correct. It's nothing with the script itself, but rather with Unity. The lighting in the newly loaded scene has not had the time to actually be baked (in other words, it hasn't really rendered). It should work fine if you make a build and test it out. It's just a problem in the Editor. When you build, if you look in the little window that shows, it says something about building lighting or something like that for a certain scene. Just follow what @dsabatier said and it should work.

avatar image
1

Answer by dsabatier · Mar 06, 2018 at 08:51 PM

Can you post the code you're using to switch scenes? It sounds like you are perhaps loading the scene additively. Is that what you want?

You'll want to do something like this if not:

SceneManager.LoadScene("SceneName", LoadSceneMode.Single);

or if you really need to, just Destroy the object in the same call as the Load using Destroy(gameObject)

Comment
Add comment · 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
0

Answer by KingKamal · Mar 07, 2018 at 05:37 PM

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class LevelManager : MonoBehaviour {
 
     // Use this for initialization
     void OnTriggerEnter(Collider ChangeScene) 
     {
         if(ChangeScene.gameObject.CompareTag("Player"))
         {
             Application.LoadLevelAdditive(1); //1 is the build order it could be 1065 for you if you have that many scenes
         }
     }
 
 }

@dsabatier

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 dsabatier · Mar 07, 2018 at 07:46 PM 0
Share

As already mentioned by the accepted answer, you'll probably want to use Scene$$anonymous$$anager.LoadLevel(string scenename) ins$$anonymous$$d. I'm surprised to see Application.LoadLevel at all. If I'm not mistaken that has been deprecated for ~3 years now :)

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

82 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

Related Questions

how to link scenes ? 4 Answers

Fade In each level 1 Answer

Should i invest in level prefabs instead of scenes? 3 Answers

remembering variables between scenes 2 Answers

Objects disappearing and scripts not working in 2 scenes. Corrupt scenes? 1 Answer


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