- Home /
Unity detect other tagged object
Say I was making a turret in a multiplayer game, and the turret aims at the tag 'turret'. Since it's multiplayer, and both turrets are exact copies, my own turret also needs the tag 'turret' for the other players turret. Is there a way to make it so it doesn't go for my tag, but it goes for the other player's tag?
Not a very informative question, so I'll just give a very basic example. Check if the object holding the tag is yours or not.
if(target.gameObject != this.gameObject)
{
//Aim Code
}
Answer by zombience · Aug 08, 2013 at 11:33 PM
I would probably have each turret class contain an ID or some variable linking it to the player.
Then, when you run code that decides whether to attack or not, do something like
if(otherTurret.GetComponent<Turret>().playerID != myPlayer.playerID)
Shoot();
else
DontShoot();
Your answer
Follow this Question
Related Questions
Multiple player spawnpoints 0 Answers
Entering multiple variables into a function 1 Answer
Same script not working on all objects 1 Answer
Why does one script not work on multiple gameobjects? 3 Answers
Multiple Targets Using Tags 1 Answer