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
0
Question by Loki_illusions · Dec 14, 2016 at 01:48 AM · collisionscene-changerestart

Won't go to next scene

I have a skydiving game where I want the game to reset to the start menu so long after the player touches down. I have this code that I think should work, but for some reason isn't.

 void OnCollisionEnter (Collision collision){
             if (collision.gameObject.tag == "terrain")
                 Invoke ("restart", 2);
         }
     
         void restart(){
             SceneManager.LoadScene ("Start Menu");
         }

I double checked that all of the tags are right, so it isn't that, and no errors are coming up when I try to debug it. Any ideas as to what could be going wrong?

Comment
Add comment · Show 2
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 Filhanteraren · Dec 14, 2016 at 01:50 AM 0
Share

Add a debug in your restart method to see if it gets called

avatar image Loki_illusions Filhanteraren · Dec 14, 2016 at 02:06 AM 0
Share

How would I do that? Sorry, haven't done any coding before and have gotten rather lost.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Pengocat · Dec 14, 2016 at 03:24 AM

Have you added the "Start Menu" scene to the "Scenes in build" list in the Build menu?

It is done by opening the scene "Start Menu" and then open the "Build settings" Ctrl+Shift+B and then click the "Add Open Scenes" Button.

To Figure out if the Method is running like Filhanteraren mentions add Debug.log("Whatever"); to the restart method and/or OnCollisionEnter method.

     void OnCollisionEnter(Collision collision)
     {
         if (collision.gameObject.tag == "terrain")
             Invoke("restart", 2);
         Debug.Log("OnCollisionEnter got called");
     }
 
     void restart()
     {
         SceneManager.LoadScene("Start Menu");
         Debug.Log("restart got called");
     }

As a sidenote collision.gameObject.CompareTag("terrain") is better to use than collision.gameObject.tag == "terrain" in regards to GC allocation.

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 Loki_illusions · Dec 14, 2016 at 03:56 AM 0
Share

Yeah, and it will go from the menu to the game scene just fine- part of what was baffling me about why the other way wasn't working.

Thanks for explaining how to do the debugger, somehow neither the OnCollisionEnter or the restart is getting called. I ended up changing it to invoke the restart when they got below a certain height and that is working for now, although still curious as to why the other way won't work.

Thanks!

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

120 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

Related Questions

Showing a restart screen on contact with an object and more... 1 Answer

How can i restart a script on collision ? 1 Answer

Change scene on collision C# 2 Answers

Somethings Wrong After Restarting Scene 1 Answer

Boolean sets itself to false when using layers. 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