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 bibbedfour7125 · Aug 21, 2014 at 10:55 AM · javascript

JavaScript collision code problem.

This very simple piece of code is supposed to change levels when the game object it's attached to hits a specific game object. The problem is when the two objects collide the scene doesn't change. Here is the code:

 #pragma strict
 
 function OnCollisionEnter(CrystalCollision : Collision){
         if(CrystalCollision.gameObject.name == "Crystal"){
                 Application.LoadLevel(0);
         }
 }


-Thanks

Comment
Add comment · Show 4
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 rutter · Aug 21, 2014 at 05:20 AM 0
Share

Two things I'd check, up front:

  1. Is LoadLevel being called in the first place? You could stick a simple Debug.Log("Here") right next to it, just to be sure.

  2. Do you have any levels set up in your build settings? LoadLevel only works with those levels.

I'm hesitant to let this through the moderation queue because it's a frequently asked question. It's not a bad question, we're just trying to cut down on the number of duplicate threads in this area of the site. If you have anything else to add, feel free to comment here; if not, I'll drop the question from the queue in a little while.

If you can't find help, here, you can always try the forums or look up some tutorials online.

avatar image gauge2727 · Aug 21, 2014 at 11:36 AM 0
Share

You haven't provided enough information really to solve this issue. As rutter said, you should check if the collision even calls Application.LoadLevel() by dropping a Debug.Log statement.

However, you could be overlooking the fact that if you are making a 2D game, you need to use the 2D variation of OnCollisionEnter.

I don't know if you're making 2D, because you didn't include that information, but it's a fairly common problem. If nothing said so far fixes/identifies the problem, post back more information.

avatar image bibbedfour7125 · Aug 21, 2014 at 01:33 PM 1
Share

Ok so I's using 3D(sorry for not including that info) and I replaced the LoadLevel with Debug.log to see if it's being called and it's not :/ Edit: I accidentally on my rig body turned on "is kinematic"

I fixed it :/

avatar image Landern · Aug 21, 2014 at 01:40 PM 0
Share

Is the OnCollisionEnter being called? $$anonymous$$ore Debug.Log:

 #pragma strict
  
 function OnCollisionEnter(CrystalCollision : Collision){
         Debug.Log("OnCollisionEnter invoked");
         Debug.Log("Collided with game object named: " + CrystalCollision.gameObject.name);
         if(CrystalCollision.gameObject.name == "Crystal"){
                 Debug.Log("Loading Level");
                 Application.LoadLevel(0);
         }
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by aress · Aug 21, 2014 at 02:16 PM

Try to use CrystalCollision.gameObject.name.Equals("Crystal") to compare the string

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

6 People are following this question.

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

Related Questions

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Camera Follow 1 Answer

GUI.Drawtexture Overlaping Other GUI.Drawtexture. 1 Answer

Turn all objects in the array to make same thing 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