• 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 FigBingers · Sep 11, 2020 at 03:30 PM · c#2dcollision2d

How do I do anything with a collision event?

Hello,

I have been trying to get it so that the player object can collect a coin (In 2D). I have already successfully used a particle system to create a gun and have it so that when it hits an enemy it sends a messages to call damage. So when I went to try and do a similar thing with 2 GameObjects instead of a particle and a GameObject I figured it'd be pretty much the same, apparently not? anyways this is my problem.

I have the player and a coin, both have Rigidbodies and 2D colliders, and I haven't made either of them Kinematic, mostly because I want them to both still have physics. What I'm asking is how do I use the collision to get information / pass information on. I tried using OnCollisionEnter(Collision collision) and then in there trying to Debug.Log(collision.gameObject.tag) or a million different variations of that but I can't seem to get anything to print to console. Even if it's just a string when any object collides with it.

Sorry if this is a bit of a ramble, I'm trying to describe as much of the situation and what I've done as possible because I don't really know where the error could be. Please help, thanks in advance :)

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
1
Best Answer

Answer by N-8-D-e-v · Sep 11, 2020 at 04:39 PM

Here's a checklist for you

  1. Do both of the objects colliding have some kind of collider attached?

  2. Does one of the objects have a rigidbody attached?

  3. Make sure you aren't checking collision.gameObject.tag make sure you are checking collision.collider.tag

  4. Both colliders must have "isTrigger" unchecked

  5. If you are using 2D Colliders, make sure you have a 2d rigidbody on one object

  6. if you are using 2d, then make sure it looks like this

void OnCollisionEnter2D(Collision2D col) { }

Comment
Add comment · Show 4 · 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 FigBingers · Sep 13, 2020 at 10:53 AM 0
Share

I got it! Thanks a lot :D

I wasn't using 'OnCollisionEnter2D(Collision2D col)'.

Thanks again :)

avatar image N-8-D-e-v FigBingers · Sep 13, 2020 at 12:06 PM 1
Share

awesome! Glad I could help

avatar image FigBingers · Sep 13, 2020 at 10:53 AM 0
Share

Also can I say that the checklist was a great tool to tick through :P

avatar image N-8-D-e-v FigBingers · Sep 13, 2020 at 12:07 PM 1
Share

I'm glad :)

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

202 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 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 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

My OnTriggerEnter2D(Collider2D other) not working 1 Answer

OnCollision2D will not work for me 1 Answer

How can I find the name of the tile that I collided with in 2d? 1 Answer

Bullet hit the collider of a child object 1 Answer

Multiple Cars not working 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges