Sprite not disappearing on collision with character

I am trying to use the following code to make my sprite disappear when touched by the main player but it doesn’t seem to work. I am new so an explanation to the answer would be appreciated.

void OnCollision2D(Collider2D Player)
	{
		if(collider2D.gameObject.tag == "Player")
		{
			Destroy (gameObject);
			gameObject.renderer.enabled = false;
		}
	}

You’ve named your Collider2D “Player”, so that is variable you need to reference, to prevent confusing it with your tag, use lower case and call it “collision”.

This is what your code should look like:

void OnCollision2D(Collider2D collision)
     {
         if(collision.collider.tag == "Player")
         {
             gameObject.renderer.enabled = false;
         }
     }

Hope that helps.