[C#] Check the Tag of gameObject what this script is applied to

Hey Guys, need some help on a silly simple problem:

Ive got a healthmanagment script for more than one gameobject.
Now i want to check the tag of the gameObject so I can do diffrent things depending on what gameObject was hit or something.

like ( gameobject.tag == “enemy”) or so

That will (almost) do what you want… perhaps a switch statement?

 switch (gameObject.tag) {
  case "enemy" :
    break;
  case "player" :
    break;
}
1 Like

If you are really lazy and inside a MonoBehaviour you can just use tag instead of gameObject.tag

1 Like

I am really lazy, and I would do it this way, but I was challenging myself to use as much of OP’s code as possible. I think I’m at 100% of characters. Achievement unlocked!

Edit: oop, except the equal signs.

1 Like