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 cardinal170 · Nov 03, 2015 at 05:41 PM · 2dscene2d-platformerchangescipting

Switching Scenes in 2D

Alright so I finally started scripting on my own and people keep telling me this is one of the easier questions, so I have a long road ahead of me. Anyway Im trying to switch scenes in unity 2d

      void OnTriggerEnter2D (Collision2D Colider)
  {
      if(Colider.gameObject.tag == "Player")
      Application.LoadLevel(level);
  }

this script isn't working because when I hit the object with my player I don't switch scenes, I have the scene in my build, is Trigger is checked and it has a Rigidbody2D

What am I doing wrong? How can I avoid this in the future?

Comment
Add comment · Show 9
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 meat5000 ♦ · Nov 03, 2015 at 12:18 AM 0
Share

And you are testing it with a Player gameobject whos tag is set to "Player"?

Does this player have collider and non-kinematic rigidbody?

avatar image cardinal170 · Nov 03, 2015 at 11:09 AM 0
Share

Yes it has a 2D box collider and a non kinematic rigid body but when you mean if the tag is set to "Player" does it have to be in quotes? @meat5000

avatar image KdRWaylander cardinal170 · Nov 03, 2015 at 12:16 PM 0
Share

No it shouln't be inside quotes :)

avatar image cardinal170 KdRWaylander · Nov 03, 2015 at 08:21 PM 0
Share

Good cause its not inside quotes but it still isn't working

avatar image OctoMan · Nov 03, 2015 at 08:39 PM 0
Share

Try to set level to an integer which is the level you need to go to. And test again.

Application.LoadLevel(1);

The number can be seen and organized in File> Build Settings> Scenes in build.

If the level you want to load is not in, open the scene with the level and click on Add Current.

avatar image cardinal170 OctoMan · Nov 03, 2015 at 08:45 PM 0
Share

Sadly that didn't work but I get this error that says Script error: OnTriggerEnter2D This message parameter has to be of type: Collider2D The message will be ignored.

avatar image OctoMan cardinal170 · Nov 03, 2015 at 08:48 PM 1
Share
 void OnTriggerEnter2D (Collider2D Colider)
   {
       if(Colider.gameObject.tag == "Player")
       Application.LoadLevel(1);
   }

try this, copy/paste all

Show more comments
avatar image killerstreak · Nov 19, 2015 at 12:40 PM 0
Share
  1. Does the player gameobject have an actual 2D collider?

  2. not sure about this, but I believe it should be Colider2D.gameObject.tag

1 Reply

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

Answer by yuzriekhalid · Apr 07, 2016 at 10:26 AM

If I'm not late to answer this, void OnTriggerEnter2D (Collider2D Colider) is the part where you need to fix. If you want a collision then do void OnCollisionEnter2D (Collision2d collision)

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

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

7 People are following this question.

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

Related Questions

How To Do Basic 2D Movement? 1 Answer

2D player slower on ground than in air 1 Answer

2D Platformer Projectile wont face mouse position? 0 Answers

[SOLVED] Ghost enemy AI that follows the player by copying the players position 0 Answers

how I change this Js code for 2D 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