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
2
Question by mangohack · Jun 20, 2011 at 11:28 AM · loadlevelswitch scenes

how to switch between scene

hi everyone, im trying to switch from one level to the other here is my code

var myLevel : String;

function OnCollisionEnter (myCollision : Collision) { if(myCollision.gameObject.name == "Floor"){ Application.LoadLevel(myLevel); } }

but it just work when i add a rigibody to my player but when i did it my player start jumping like crazy

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

4 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by BarkShark · Jun 20, 2011 at 11:53 AM

In unity go to File >> Build settings. A new window will pop up. Just hit add current to add you're current scene. You also can drag your scenes from your project folder. Then they're appear numbers next to the name of your scene. In your script use this instead:

 function OnCollisionEnter (myCollision : Collision) 
 { 
 
 if(myCollision.gameObject.name == "Floor")
 { 
 Application.LoadLevel(// The number next to the scene in the build settings window);
 } 
 }
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 mangohack · Jun 20, 2011 at 12:20 PM 0
Share

it doesn't work

avatar image BarkShark · Jun 20, 2011 at 12:50 PM 0
Share

And if you change the collider to a trigger? In your script you just have to use OnTriggerEnter ( myCollision : Collider)ins$$anonymous$$d of

function OnCollisionEnter (myCollision : Collision)

avatar image NuclearKitCat · Jun 28, 2017 at 10:06 AM 0
Share

yup doesent work u know

avatar image
4

Answer by EJ6612 · Jan 05, 2017 at 08:18 AM

It has now been updated to this:

 using UnityEngine.SceneManagement;

 // In a function
  SceneManager.LoadScene(1); //replace the int with level number


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 edovman · May 30, 2015 at 07:07 PM

yes you should make it a trigger so the player doesn't bounce off

Comment
Add comment · Show 2 · 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 DivineExpertise · Jul 09, 2017 at 10:49 AM 0
Share

I have spent countless weeks making countless scenes on a game I have been developing, and I can't get any damn javascript script to switch me between scenes by making contact with an objects collider. I was really hoping that you guys could help, but none of your scripts work, it keeps saying that it was expecting something different, and if I switch it to what it was expecting it just screws the script even more. Please, any 'updated' assistance would be greatly appreciated.

avatar image DivineExpertise DivineExpertise · Jul 09, 2017 at 10:52 AM 0
Share

Damn me, I shouldn't ask such $$anonymous$$iscule questions. I take it back, I actually found a tutorial on how to do so. Thanks anyways.

avatar image
0

Answer by Vollmondum · Jul 09, 2017 at 10:56 AM

It's currently

 SceneManagement.SceneManager.LoadScene("sceneName");

Comment
Add comment · Show 2 · 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 Vollmondum · Jul 09, 2017 at 11:01 AM 0
Share

$$anonymous$$oreover no rigidbody is required if one of collider is set to "Is Trigger". The other one shouldn't be one. Another issue happened the other day, it couldn't detect collision between two simple shape colliders. You want this:

     function OnTriggerEnter(myCollider:Collider)
     {
     if(myCollider.name == "whatever")
     {
     Scene$$anonymous$$anagement.Scene$$anonymous$$anager.LoadScene("sceneName")
     }
     }

Or ins$$anonymous$$d of "sceneName" you can type the number of your scene in build settings

avatar image yorgey386 · Jan 03 at 05:16 PM 0
Share

I tried that, but Unity gave me "Assets/Scripts/ExitCredits.cs(15,13): error CS0103: The name 'SceneManagement' does not exist in the current context" Here is my code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class ExitCredits : MonoBehaviour
 {
     public bool shouldExit = false;
    
     // Update is called once per frame
     void Update()
     {
         shouldExit = Input.GetKeyDown(KeyCode.Escape);
         if (shouldExit)
         {
             SceneManagement.SceneManager.LoadScene("Entrance");
         }
     }
 }



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

8 People are following this question.

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

Related Questions

How to teleport to different scenes? 2 Answers

How to take a GameObject from A scene to B scene when the GO was instantiated? 1 Answer

How to Make the Game Go to the Next Level When the Music Stops 2 Answers

Unity script to open a new scene 3 Answers

Scene Switching? 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