- Home /
Only do something if it has the same tag as the player
Hello everyone,
I am using photon for making my game, I want the players to be able to do something with only objects that have the same tag as the player game object, can I achieve that? something like that if (gameObject.tag == theplayerprefab.tag){ //do something }
something like that : if (gameObject.tag == theplayerprefab.tag){ //do something }
Because I will have 2 players in the scene, blue and red, the red should control the red components while the blue controlls the blue ones. But, each component can change color (from blue to red or red to blue) so it means change the owner.
Thanks ^^.
Answer by EnigmaticCrow · Oct 07, 2018 at 08:34 PM
You should only use the == operator to compare numbers. (or when checking if two references are exactly the same)
Just remember to use the Equals() method instead of the == operator for strings:
if (gameObject.tag.Equals(theplayerprefab.tag)){ //do something }
Answer by JusSumGuy · Oct 07, 2018 at 09:10 PM
if(gameObject.CompareTag(player.tag))
{
DoSomething();
}