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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by I_hate_c_sharp · May 10, 2014 at 12:59 PM · 2djavascriptontriggerenter2dcollectible

OnTriggerEnter2d not working

I'm creating collectibles for in my 2d platformer, but something's wrong. I have added a circle collider to my collectible and I checked "Is Trigger." I added a javascript to my collectible but something is still going wrong. I don't get any errors or anything, my player just runs straight through the collectible. Here's my script:

 function OnTriggerEnter2d (info: Collider)  
     {  
         if (info.name == "player") {  
             Destroy(gameObject);  
         }   
 }
Comment
Add comment · Show 6
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 D3ltaVyyb · May 10, 2014 at 01:17 PM 0
Share

$$anonymous$$ake sure your GameObject's name is exactly that "player" with a common p. $$anonymous$$ake sure your player also has a collider on. Info has to call on "Collider2D" not "Collider"

avatar image I_hate_c_sharp · May 10, 2014 at 01:44 PM 0
Share

Thanks for that, I overlooked it but my player still goes straight through my coin.

avatar image felixpk · May 10, 2014 at 01:46 PM 0
Share

Does your Collectable or the Player have a RigidBody2D attached? If one of them has, is "Is$$anonymous$$inematic" may checked?

And another Tip, don't look through the names of the GameObjects but ins$$anonymous$$d check the Tag of an Object, like info.gameObject.tag == "Player"

avatar image I_hate_c_sharp · May 10, 2014 at 02:59 PM 0
Share

yeah, I have the is$$anonymous$$inematic checked on my collectable

avatar image felixpk · May 10, 2014 at 04:54 PM 0
Share

Then uncheck it and set the Gravity Scale to 0. The option is in the same menu as the is$$anonymous$$inematic.

Show more comments

3 Replies

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

Answer by I_hate_c_sharp · Jul 01, 2014 at 01:55 PM

Hey I found the problem. I was using a script I hadn't looked into for some time, and it changed is kinematic. I changed that and yay! It works! I'm very sorry to everyone who spent time on this post :( stupid me

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
avatar image
3

Answer by Pyrian · May 11, 2014 at 08:46 PM

OnTriggerEnter2D needs that D at the end to be capitalized.

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 I_hate_c_sharp · May 13, 2014 at 01:54 PM 0
Share

I cinda got that

avatar image MasqueNoMercy · Nov 28, 2014 at 05:39 PM 0
Share

This was my problem too, didn't capitalize

avatar image Nombs · Jan 26, 2016 at 07:24 PM 1
Share

Thank you for this. I tried an embarrassing amount of other things before finding your simple solution haha.

avatar image
1

Answer by spiralfire11 · May 13, 2014 at 09:08 PM

Usually, i use this script when it comes to collision :

using UnityEngine; using System.Collections;

public class Collision : MonoBehaviour { void OnTriggerEnter(Collider other) {

if(other.tag == "Bullet") { Destroy (gameObject); Destroy(other.gameObject); } else { Destroy(other.gameObject);

Application.LoadLevel ("death"); } }

}

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 I_hate_c_sharp · May 18, 2014 at 06:09 PM 0
Share

could u tell me how to do that in javascript?

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

25 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

Related Questions

Making the players head face toward the location of the mouse? 1 Answer

Mouse Click to keyCode 1 Answer

2D Animation with JavaScript (Android). Help! 0 Answers

[JavaScript] Making an image sprite change upon button click? 1 Answer

How do you AddForce to a rigidbody2D in the direction of a joystick? 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