0
votes

I am building a 2d game and I run this code with a collider on both the other objects (on trigger: on to the other object) but nothing works)The other object is name Coin and also it has the tag Coin. I added kinematic rigid body to the coin and still no work :( (If I deleted it still the same). Also, my player has to colliders and the collision detected on both coin and player are discrete. Also, they are prefabs both

void OnTriggerEnter2d(Collider2D other) {
 Debug.Log("detected");
 if (other.gameObject.CompareTag("Coin")) {
  other.gameObject.SetActive(false);
 }  
}
2
Possible duplicate of this question, this one, this one, this one, maybe this one? - Hellium
@Hellium no all of that has been checked but still nothing(Also its 2d) - Tr4pper Rapper

2 Answers

1
votes

Typo mistake: instead OnTriggerEnter2d try OnTriggerEnter2D. with a capital D. ;)

0
votes

In order to get a OnTrigger collision triggered, you must have the following requirements: 1-The 2 objects need to have a collider attached it. 2-Only one of the objects needs to be a trigger 3-One of the 2 objects must have a rigidbody attached to it.

Did you fulfill the requirement n°3 ?

Typo mistake: instead OnTriggerEnter2d try OnTriggerEnter2D. with a capital D. ;)