Adding Health to a Player

I have a feature in my game where a laser is firing at the player. I want the player to also be able to collect objects that would increase the players health. Here is the code that I used to try to increase the health:

void OnTriggerEnter2D(Collider2D other)
         {
           if(other.gameObject.name == "Coin")
           {
              _healthPoints += 10000;
         }
     }

I have also tried tags but that has not worked either.

I am happy to report back that I got it to work. I realized that the tag code was slightly different so I just modified the code above replacing name with tag and it worked.

void OnTriggerEnter2D(Collider2D other)
         {
           if(other.gameObject.tag == "Coin")
           {
              _healthPoints += 10000;
         }
     }

If you’re using name make sure the name is the same as the name of the gameobject with the collier on it, it won’t detect a parent or child object’s name

Okay thanks. I am fairly certain the name was correct but I will check again on that.