OntriggerEnter2D not working unity 5.5

Hi,

I am making a simple prototype of 2D game platform.

But I really don’t know what I am doing wrong to make the collectible item work.

I’ve tried the most variations and combinations of setups that I can imagine on the Unity, but without success.

1 - Player → Tag “Player” → Rigidbody2D (Dynamic), Box Collider 2D (checked and unchecked “Is Trigger”).

2 - Collectible item → Tag “Mushroom” → Rigidbody2D (Dynamic/Kinematic/Static), Box Collider 2D (checked and unchecked “Is Trigger”).

C# → Method (OnTriggerEnter2D): Script only applied to the collectible item “Mushroom”

void OnTriggerEnter2D (Collider2D other)
{
	if (other.gameObject.CompareTag ("Mushroom")) 
	{
		Debug.Log ("Found something: " + other.name);
		other.gameObject.SetActive (false);
	}
}

Debug doesn’t show anything and the active/deactivate doesn’t work.

I found some links here in the forum and tried to apply the solutions, but without success too.

I would like to know if there is some issue/bug with the version of the Unity (5.5) or if I am doing something wrong.

Thanks in advance.

hi, try using this:

     void OnTriggerEnter2D (Collider2D other)
     {
         if (other.tag == "Player") 
         {
             //As the script is in the mushroom the object that collides with it is
             //the player so the name and the object you have to delete is the             
             //mushroom one.

             Debug.Log ("Found something: " + transform.name);
             transform.gameObject.SetActive (false);
         }
     }

and make sure the collider of the mushroom is checked as a trigger.

@scrubuch, thank you very much.

I really spent today trying to make it work and I almost performed a downgrade.

It worked smoothly.

My logic to organize the steps of the collision it was wrong.

And I moved the script to the player, it makes more sense because the player is moving and is going to hit others objects.

Once again, thanks for your valuable support.