My collider2D don't work
Hello I was making a script wich contain 2d collision
but for some unknow reasons ,when my gameObjects enter in collision, nothing happen, not even the debug.log is working (and i didn't find any answer that have actually helped me)
Here is my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DetecCollision : MonoBehaviour {
public GameObject player;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update () {
player = GameObject.Find ("player"); }
void OnCollisionEnter2d(Collision2D col) {
if (col.gameObject.name == "player") {
Debug.Log ("hello");
Destroy (gameObject);
}
}
}
(sorry in advance for the bad english)
Do your objects have 2D colliders?
Like any kind of 2D colliders ex. Box Collider 2D.
Yes the "player object have a BoxCollider2d and a Rigibody2D
and the object with wich the collision is suppose to happen have a boxCollider2D
Both objects need to have 2D colliders. Put breakpoint on line:
if (col.gameObject.name == "player") {
Or Debug.Log above it and check if OnCollisionEnter2d executes at all.
Answer by Merrio · Nov 26, 2017 at 10:53 AM
Hello again After a few reset, the collider have decided to work for some unknow reasons
So I guess my problem is solved
Your answer
Follow this Question
Related Questions
Co ordinates of 2D object/image,Get Co ordinates covered by Object 0 Answers
Character hits invisible ghost collision when jumping against objects while pushing against them 0 Answers
2D Character Falling Through Ground 0 Answers
Jitter with Tilemap Collider's but no Jitter on standard Box Collider 1 Answer
Easy Collider issue 1 Answer