- Home /
How to tag?
Hello Unity3D.I have a question about Tagging?In multiplayer local 4 player,Is is possible to make a character change the tag when fighting another character with a different tag?For example.Im playing with a friend locally and the characters cameras are split screen and i'm player 1 and my character is tagged player but on my screen its makes the opponent tagged as enemy.and on my friends screen he is player 2 and on his screen his character is tagged player and im tagged enemy,meaning on his screen he sees me as the enemy and on my screen i see him as the enemy.Can you make it that when someone plays multiplayer split screen the tags change depending on whos the player?If yes,Can anyone please tell me how?
When you speak about tags, are you referring Unit's tag ? If yes, and if you are on a splitted screen, it's not possible I guess since a gameobject can have only one tag in the entire scene of a same game.
What do you want to do with these tags ?
I need the tags for auto lock on a character.And dang its not possible so i got to find another way
Even if it's not possible with Unity's tag, you could try to make a custom tag as attribute of your players.
Else, you could simply make your auto lock on gameobjects with the same tag as your player except on your player itself (since the other players are necessarily enemies)
Wait how do i make it that i can auto lock on gameobjects with the same tag as my player except on myself? Becuase the last time i used findwithtag it found with both my character and the enemy having the same tag,it tagged myself xD.Also is there another way that i can find an object on the field without using tags or findgameobject named?
why not create a tag controller script that can handle 4 or so tags set as strigs, and then is tested against a call from another script to see if any of the tags in the controller match the tag it's looking for? or you could simply create a second prefab for player, and have the game test if for tags "player1" and "player2" i.e making player 2 camera find player2 tag on the duplicate instantiated prefab?
Answer by Mark Gossage · Jun 24, 2015 at 04:03 AM
You don't want 'tag' as per the Unity engine term. These are designed not to be changed at runtime (AFAIK). What you really want is a Team. So just build one.
class Team: MonoBehaviour
{
public int team=0;
}
You can then attach this script to each player & its a just GetComponent() to access which team you are in & build your game rules accordingly.
Im sorry can you elaborate more on the $$anonymous$$m subject here ?because i really want to get a firm grasp on this
say you start a match with $$anonymous$$m blue (1) and $$anonymous$$m read (2) every player will have the $$anonymous$$m script on them. when you attack an opposing $$anonymous$$m member you get the $$anonymous$$m members component which is the $$anonymous$$m script. and once you have that you check their $$anonymous$$m variable against yours and if they are the enemy $$anonymous$$m then continue with the attack script;
ok i think i understand what your saying.you want me to make 4 copies of the of the same character and make them each have the $$anonymous$$m script but if i select $$anonymous$$m on they become $$anonymous$$mmates and they attack anyone thats not on their $$anonymous$$m?
Basically yes. In Unity, there is not 2 copies of the world, there is only one copy of the world. So in the world you have a character game object with a Team script which says '$$anonymous$$m=1' and you have a second character game object with a Team script which says '$$anonymous$$m=2'. You can write the code such that the two characters can fight each other because they are on different $$anonymous$$ms. But if you changed them to both be '$$anonymous$$m=1' then they could be the same $$anonymous$$m and you can write your game logic accordingly (remove friendly fire etc).
Wouldn't that make take up more megabyte?$$anonymous$$eaning,is the strategy that the professionals use?If so is there anything i do to limit the coding as much as possible?