GetComponent<PlayerHealth> vs Tags

PlayerHealth playerHealth = other.GetComponent();

    if (playerHealth == null) 

{

}

vs

if(otherObject.tag == player)
{

}

I used tags instead of what was done in the video to accomplish the same thing. Is one way better than the other or is it a personal preference thing or does it depend on the situation?

Hi Tamio,

Thanks for the great question.
Its personal preference but also tags can be typoed and you wouldnt get any errors to tell you otherwise.
In getting the player health script it will tell you if there is an issue and will give more of an idea of why something is not working.

Hope this helps

1 Like

I’ll keep that in mind. Thanks for the reply!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms