Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by crusherxman · Apr 12, 2014 at 09:27 PM · colliderplayerscenechange

Load scene when colliding on GameObject

I've been looking for a few tutorials and other Unity Learn documentations, I couldn't find what I was exactly looking for. My script doesn't have errors, but it doesn't work at all.

So, I have my character ready, a few GameObjects and a "Game Over" scene. Whenever I collide with red sphere (otherwise called, "GravityBall_Red"), I should be in the "Game Over" scene (called "LevelRetry"). Now here's the script:

 function OnCollisionEnter(other : Collision){
 if(other.gameObject.name == "GravityBall_Red")
 Application.LoadLevel ("LevelRetry");
 }

If there's anything else you guys should need, I'd be good to give you a little more info.

Thanks

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

1 Reply

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

Answer by nicolasjr · Apr 12, 2014 at 09:30 PM

Hi Crush,

So, based on your code, I can only say that the problem is that you're not even detecting the collision, for some reason. Are you sure your condition is being reached? I mean, if you debug inside the if condition, it'd be reached?

There are some details about collisions you should pay attention to, but the most important is that the gameobject from the script you're verifying collision must have Rigidbody component.

Can you check that?

Comment
Add comment · Show 6 · 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 crusherxman · Apr 12, 2014 at 09:41 PM 0
Share

About the RigidBody, I've tried adding one but it didn't make a difference. I'm not getting info on the Console Log, although you're saying I should add more info to the script, like tell the script when the player collides with the GameObject?

avatar image nicolasjr · Apr 12, 2014 at 09:44 PM 0
Share

Yes, I'm telling you to create a Debug.Log() inside the if statement that verifies the load of the other level. This way you'll know if the collision is being detected or not by unity!

avatar image crusherxman · Apr 12, 2014 at 09:49 PM 0
Share

Alright, still not getting anything from the log. I guess you're right, the condidtion doesn't reach and doesn't detect it.

avatar image nicolasjr · Apr 12, 2014 at 09:54 PM 0
Share

Exactly. So, you've got to check the collisions.

Go from the basic:

  • The object that detects collision needs rigidbody;

  • The other object needs collider;

  • Is the other object really with the same name you're verifying? ;

  • etc....

Sometimes the problem is where you less expect.

avatar image crusherxman · Apr 13, 2014 at 02:48 PM 0
Share

Got it! $$anonymous$$y tag had a space at the end, finally works.

Thanks for your help :)

Show more comments

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

22 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Animation play when player collides/hits an GameObject 0 Answers

Have script detect which collider 2 Answers

Script works for NPCs, but not Player 1 Answer

When "Player" enters a trigger = flashlight off 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