- Home /
Check if Transform Tags are Identical
Hey, so I was wondering if it was possible to check on hit (RayHit) if the hit objects transform tag is equal to that of the player? Or even better: If the hit object is the player. In context, I don't want the player to receive the full damage of an explosion or shot when he is hit by his own weapons or those of friendlies. Can anyone help me? Thank you in advance!
if (hit.collider.tag == "Player")
or
if (hit.collider.name == "Player")
In $$anonymous$$ultiplayer, how would I do this? Could I give the collider a different name as well? That would solve all my problems...Say for example if I made the tag $$anonymous$$m 1 and then the collider something different.
It's better to use CompareTag ins$$anonymous$$d of string comparisons.
yes, when you instantiate all the players for the $$anonymous$$ms you can change their collider's names to either Team 1 or Team 2 etc.
You could have the tag be "Team1" and then give individual names to each of the players game objects. Or you can add the data to a script attached to each player, and then query the script:
ScriptInfo si = hit.collider.gameObject.GetComponent<ScriptInfo>();
if (si != null) {
if (si.myName == "Fred") {
// Do something
}
}
Answer by Borzi · Jun 20, 2013 at 07:11 AM
Okay so what I ended up doing is the following:
I added Tags for to the players for Teams and gave the Players names and used the following Code:
if(Hit.transform.gameObject.name == "Player1")
Your answer
Follow this Question
Related Questions
How to handle movement in a multiplayer FPS? 0 Answers
Making a Model move with the Mouse 1 Answer
Multiplayer FPS Tutorial 1 Answer
When a host player changes his weapon all players get switched to it 1 Answer
Making a fps online game 3 Answers