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 /
  • Help Room /
This question was closed Jun 07, 2016 at 11:10 AM by Hellium for the following reason:

Duplicate Question

avatar image
0
Question by Wizachu248 · Jun 07, 2016 at 09:06 AM · triggersnewbiecollisionsload scenenext level

Moving to Next Level on collision

hi I need help getting to the next level on my puzzle game, I want to get it so when it touches the exit it load the next level

 using UnityEngine;
 using System.Collections;
 using UnityEngine.SceneManagement;
 
 public class LevelLoader : MonoBehaviour {
 
     public string levelToLoad;
 
     void OnTriggerEnter(Collider other)
     {
         SceneManager.LoadScene("levelToLoad");
     }
 
 }
 

is there any other way i could do it or am i doing something wrong please help Thanks

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 JVince · Jun 07, 2016 at 10:33 AM 0
Share

At first, I think you have to check that does the collider collide anything by put this line inside the OnTriggerEnter before the Scene$$anonymous$$anager line: Debug.Log("Has collide " + other.name); I wonder that the IsTrigger check box of you game object are not checked yet, if not yet, check it . Hope this help

1 Reply

  • Sort: 
avatar image
0

Answer by Eudaimonium · Jun 07, 2016 at 09:51 AM

You are declaring a variable called levelToLoad, but then in your function you're giving it a hardcoded string (as denoted by quotes), instead of actual variable.

Change your line to:

 SceneManager.LoadScene(levelToLoad);

And make sure you add your scene to build order.

  • Open up the scene you wish to load next in your editor, so you can see it.

  • Open File -> Build Settings, and click "Add Open Scene".

  • You should now see both the scene you are coming from (assuming you added it), and the scene you wish to load in your build order.

Also, my advice is to use a scene index to load scenes, instead of a string representing the scene name.

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 Wizachu248 · Jun 07, 2016 at 10:03 AM 0
Share

no that did work you wouldn't know of another way to do it?

avatar image Eudaimonium Wizachu248 · Jun 07, 2016 at 10:05 AM 0
Share

What do you mean by this?

Does it throw any error messages? Does the script correctly get called? Try putting a print("Collision"); statement before your Scene manager line, see if that gets printed in the console.

And no, Scene $$anonymous$$anager is the way to load new levels and scenes in your Unity game. Why do you need another way to do it?

avatar image ankitdave · Jun 07, 2016 at 11:03 AM 0
Share

have you write your next scene name to public variable levelToLoad in inspector where you attach your script?

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

next level 1 Answer

Frogger Logs OnTriggerEnter2D OnTriggerExit2D 0 Answers

Move to the next level once all with "enemy" are dead with tag 2 Answers

Using OnTriggerStay for entering, staying or exiting 2 Answers

Use a string to call a class 2 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