• 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 Gusic · Mar 14, 2015 at 02:34 PM · c#2dcollision

Collision script not working (C#)

Hi Guys,

I have a collision script that works if a my coin collides with my object then the coid is destroyed. however my script isnt woking i have a respawn tag and a 2d collider on my object and i have a 2D rigidbody on my coin and a 2d collider and still its not working.

Thank You

Script

using UnityEngine; using System.Collections;

public class StopsTheCoin : MonoBehaviour {

 void OnCollisionEnter2D(Collision2D coll) {
     if (coll.gameObject.tag == "Respawn")
         Destroy (gameObject);
     
 }

}

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 Denvery · Mar 14, 2015 at 03:09 PM 0
Share

Is your OnCollision2D method invoking?

Please check (for example, with Debug.Log()) if OnCollisionEnter2d() is invoking. Place Debug.Log("sdfsf") before "if" statement and check the log.

avatar image Gusic · Mar 14, 2015 at 05:12 PM 0
Share

i did what you asked and i got no debug log messege. i think there is something wrong with the script but i dont know what. Is there any other script that can do what i am trying to do.

avatar image meat5000 ♦ · Mar 14, 2015 at 05:16 PM 0
Share

Both objects have colliders?

avatar image Denvery · Mar 14, 2015 at 05:22 PM 0
Share

Check z-coordinates of the objects. They should be the same.

avatar image tanoshimi · Mar 14, 2015 at 05:25 PM 0
Share

Rigidbody? That won't work. Add a Rigidbody2D component ins$$anonymous$$d.

Show more comments

1 Reply

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

Answer by OWEN047FTW · Mar 14, 2015 at 10:51 PM

Dude, you need to make sure that it is a 'Box collider 2D' and that 'Is Trigger' it ticked, then change 'OnCollisionEnter2D(Collision2D coll)' to 'OnTriggerEnter2D(Collider2D other)'

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 Gusic · Mar 14, 2015 at 11:23 PM 0
Share

Thank you sir

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Object following a path and colliding with other objects with physics. 1 Answer

Simple on Collision Help (C#) 2 Answers

Moving objects upwards in unity's editor-window, moves the same object automatically further on z-axis 1 Answer

2D Collision problem 1 Answer

Checking for collision with 2D objects/sprites 3 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