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 Dugat · Apr 19, 2016 at 01:12 AM · 2d2d game2d-physics

How do I get my character to go the the next level?

Hi, so I have the script in player that checks to see if the player collides with the exit, but it doesn't actually load the new map after doing so.

 private void OnTriggerEnter2D (Collider2D other)
         {
             //Check if the tag of the trigger collided with is Exit.
             if(other.tag == "Exit")
             {
                 //Invoke the Restart function to start the next level with a delay of restartLevelDelay (default 1 second).
                 Invoke ("Restart", restartLevelDelay);
                 
                 //Disable the player object since level is over.
                 enabled = false;
             }
 ........
 private void Restart ()
         {
             //Load the last scene loaded, in this case Main, the only scene in the game.
             Application.LoadLevel (Application.loadedLevel);
         }

I am just not understanding why it isn't loading the new level. If it helps, I have basically combined the code for the unity 2d procedural dungeon generation and the 2d rogue-like tutorials. Any help or suggestions would be appreciated.

Comment
Add comment · Show 5
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 Dugat · Apr 19, 2016 at 01:15 AM 0
Share

And if there are any clarifications that need to be made please let me know.

avatar image jgodfrey · Apr 19, 2016 at 01:35 AM 0
Share

So, there are a number of possible failure points. You need to figure out which one is the cause of your problem.

  1. Do you ever get inside the OnTriggerEnter2D method?

  2. Do you get inside the "if (other.tag == "Exit")" block?

  3. Is the "Restart()" method being called?

Add a Debug.Log statement in each of those areas and see which one you don't see in the console.

If you don't find the problem, report back the results for some more assistance.

avatar image Dugat · Apr 19, 2016 at 01:46 AM 0
Share

@jgodfrey thank you for that. I just checked, but I had all three messages output (one in the on trigger, one in the if statement, and one in the restart() method). It just goes to a screen that says the scene is missing a fullscreen camera, but the camera is attached to the player.

avatar image jgodfrey · Apr 19, 2016 at 01:57 AM 0
Share

Hmmm... I think the code you're using in Restart() is deprecated, but I'd think it'd work. You could try this ins$$anonymous$$d (which should be the more current way to do the same thing).

 Scene$$anonymous$$anager.LoadScene(Scene$$anonymous$$anager.GetActiveScene().buildIndex);

... And, you'll need to add a

 using UnityEngine.Scene$$anonymous$$anagement;

to the top .

avatar image Dugat · Apr 19, 2016 at 02:07 AM 0
Share

Yeah, that just did the exact same thing

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Ali-hatem · Apr 19, 2016 at 01:59 PM

@Dugat you are disabling the player object that holds this script before 1 second of calling the restart so there will be no script & no reload & what you have to do is don't disable the object since it will be loaded again or move enabled = false;to Restart ()

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 jgodfrey · Apr 19, 2016 at 02:18 PM 0
Share

Ah, yeah... Good call.

avatar image Ali-hatem jgodfrey · Apr 19, 2016 at 02:31 PM 0
Share

@jgodfrey i thought you suspected that when you asked for debug

Is the "Restart()" method being called?

but i think he didn't put it in Restart () .

avatar image jgodfrey · Apr 19, 2016 at 02:39 PM 0
Share

Hmm.... Yeah, you're right. I have my head in too many things... ;^). Anyway, according to the reply, a Debug.Log was added in Restart and the message was output to the console...

I wonder if the disabled player isn't being re-enabled when the scene is restarted...

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

80 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

Related Questions

Walking around 2D planets? 1 Answer

2D drag and throw ragdoll physics 0 Answers

How do I assign a velocity to an object on only 1 axis? 1 Answer

Is there any way to prevent Polygon collider auto generation in Unity 5.3? 0 Answers

2D Accuracy 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