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 /
avatar image
1
Question by Meegsy · Apr 28, 2017 at 02:21 AM · collisionscene-change

Change scene on collision C#

Hi, I have looked all over for something to answer my question but couldn't find anything. I want to have a sphere run into a cube and change scenes. At the moment my code is not doing anything but there are no errors either.

My code currently -

 void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.tag == "Player")
         SceneManager.LoadScene (2);
 }

I am a beginner so if you could put at least a small explanation about what you suggest that would be great. 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 GameGuy12 · Jun 09, 2020 at 05:06 PM 0
Share

the thing you want to collide with you have to put the script on and make sure it has a box collider and on the box collider make sure is trigger is checked and go to file-buildsettings and add all of your scenes then look at the scene you want to teleport to and look at the number and where it says Scene$$anonymous$$anager.LoadScene (2); change the number 2 to what number the scene was and that should be it.

2 Replies

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

Answer by Jawchewa · Apr 28, 2017 at 02:54 AM

A couple things that I would recommend looking into:

First, make sure that one of your gameobjects actually has a collider with the "Is Trigger" boxed checked. OnTriggerEnter won't fire if neither collider is a trigger.

Second, to use OnTriggerEnter, one of your two gameobjects must have a rigidbody attached. Depending on how your movement is working, you might also want to make the rigidbody kinematic.

See here for more details: https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerEnter.html

Third, one thing to consider is to use OnCollisionEnter instead of OnTriggerEnter. This way you wouldn't need Triggers or rigidbodies at all, but that may or may not be the best idea depending on your situation.

https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnCollisionEnter.html

Fourth, this is probably obvious, but make sure that the gameobject that doesn't have the script has a tag set to "Player".

And Finally, you'll also want to make sure that your scene is actually added to the build settings in unity.

https://docs.unity3d.com/Manual/BuildSettings.html

Hope at least one of these helps!

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 Meegsy · Apr 28, 2017 at 03:22 AM 0
Share

Thanks! I'll try those.

avatar image
0

Answer by kylerpc06 · Mar 01, 2019 at 04:58 PM

When i named my level even tho it was in the build settings it said it wasn't

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 Apianbelledev · Mar 18, 2021 at 12:56 AM 0
Share

Try using a string like this { public string newGameScene } void LoadScene () { SceneManager.LoadScene("newGameScene"); }

make sure in the inspector you set the string (newGameScene) to the name with the exact spelling as the scene you are trying to load to. this is one of the easiest ways to do it, although there is a way to get faster load times by using LoadSceneAsync Like this SceneManager.LoadSceneAsync("enter string here");

What this does is it loads the scene in the background sow the button or collider or trigger or whatever you have to trigger the loading, it just activates the scene into the foreground.

hope this helps :)

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

136 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

Related Questions

Won't go to next scene 1 Answer

How would I go about making a spider create a web? 0 Answers

How do I get objects to detect collisions? 2 Answers

Rotated object raycasting in wrong directions!!? 3 Answers

Objects need to collide without imparting momentum 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