OnCollisonEnter2D Not Firing after checking collider
I was trying to make a script to check if a collision. I am using:
 public class Lose : MonoBehaviour {
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
     void OnCollisionEnter2D(Collision2D col) {
         if (col.gameObject.name=="ramp") { 
 print("You lose");
          }
     }
 }
I have googled it but nothing pops up.
Answer by _Game_Dev_Dude_ · Nov 17, 2015 at 06:45 PM
When dealing with colliders there are a couple of things you have to be careful of. So check these things and hopefully you will find the problem.
- You are using OnCollisionEnter2D, this means that both the objects involved must have a Rigidbody2D component attached to them. 
- They also both need Colliders of the 2D variety. Box Collider, Sphere Collider, etc will not work. You need to use BoxCollider2D, CircleCollider2D. 
- Make sure the name of your game object is "ramp" exactly. Case matters I believe. 
Thanks I ended up seeing that the ramp game object didn't have Rigidbody2D attached. I now just added a Rigidbody2D and since I didn't wan't it to fall set all of the text input vars where 0 and made "Is $$anonymous$$intematic" checked. Thanks lots. I now will use that to do these sorts of things. Plus I didn't have to change my code!!!!
Your answer
 
 
             Follow this Question
Related Questions
Collision Detection Not Working (Unity 5.2.3) 5 Answers
Can not get my raycast to detect an object 0 Answers
How to enable a script in Play-Mode? 1 Answer
Changing an objects location 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                