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 bitthebillias · Dec 30, 2018 at 11:27 PM · levelslevel loadlevel select

How to make an exit level trigger?

I want to make a platform that when walked on exits the level and brings you back to a level selection screen. Any thoughts/resources anyone has?

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

3 Replies

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

Answer by betaFlux · Dec 30, 2018 at 11:54 PM

I tend to immitate techniques of famous games. In this case I would do it like Neverwinter Nights did it.

  • Add an empty gameobject to the scene

  • Attach a box collider to it, set it to trigger and adjust its dimensions to your liking

  • Now attach a script with the following code to the trigger object:

         public class Trigger : MonoBehaviour
         {
             public string sceneName;
         
             void OnTriggerEnter(Collider c)
             {
                 if(c.tag == "Player")
                     UnityEngine.SceneManagement.SceneManager.LoadScene(sceneName);
             }
         }
    
    

If your player's tag is "Player" and has a collider attached, it should work. Make sure to type the correct scene name into the Trigger Script inspector.

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
1

Answer by triis4924 · Dec 30, 2018 at 11:44 PM

just make an empty object with is trigger checked then make a script that looks like this:

 void OnTriggerEnter2D(Collider2D col)
     {
         if (col.gameObject.tag == "player")
         {
             SceneManager.LoadScene(sceneyouwanttoload);
         }
     }

make sure you write using UnityEngine.SceneManagement; and the player has a player tag

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 bitthebillias · Dec 31, 2018 at 12:08 AM

okay cool! that worked.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 
 
 public class Trigger : MonoBehaviour
 {
     public string sceneName;
 
     void OnTriggerEnter(Collider c)
     {
         if (c.tag == "Player")
             UnityEngine.SceneManagement.SceneManager.LoadScene("MainMenu");
     }
 
     /*public void OnTriggerEnter2D (Collider2D col)
 {
     if (col.gameObject.tag == "player")
     {
         SceneManager.LoadScene("MainMenu");
     }
 }
 */
 
 
 }

so now i ran into another problem after that:

I am using the unity first person camera in this project and when i jump back into the "mainMenu" scene, i dont have control of the mouse to select anything... Thoughts?

Comment
Add comment · Show 5 · 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 betaFlux · Dec 31, 2018 at 12:18 AM 0
Share

In your current Trigger script you may remove the variable sceneName if you directly load scene with "$$anonymous$$ain$$anonymous$$enu". Also as you added the namespaces Scene$$anonymous$$anager.LoadScene("$$anonymous$$ain$$anonymous$$enu"); is enough.

As for your problem, are you sure that the camera exists in both scenes?

avatar image bitthebillias betaFlux · Dec 31, 2018 at 12:27 AM 0
Share

it doesn't exist in both. i want to be able to enter the level through a level button menu, go play through the level. Exit. Then be sent back into the level button menu to pick the next level.

If i could regain mouse control from the camera, i might be able to get somewhere.

Eventually i want to have the next level to be unlocked by exiting the previous level.

avatar image betaFlux bitthebillias · Dec 31, 2018 at 12:43 AM 0
Share

In the level itself is the cursor hidden? If so, when entering the level selection screen, you could either disable the script that hides and locks the cursor or create a little extra script which enables the cursor again: Cursor.lockState = CursorLock$$anonymous$$ode.None; Cursor.visible = true;

Show more comments

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

98 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

Related Questions

Problems with unlocking levels 1 Answer

How to manage multiple levels in the 2D game ? 3 Answers

Level Selector not working on build 0 Answers

How to load scenes based on specific percentage? 0 Answers

manage objects through a manager script 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