- Home /
A way to code teleporters for different teams?
Hi all,
I'm having issues with the attached script. My players are instantiated under the tag "PlayerBlue" or "PlayerRed" according to which team the user selects. However, I can only seem to get one teleporting script into the game, as duplicating it and adding a "1" or something at the end just doesn't work for me. Is there any way I could just allow both tags to pass through the teleporters, but only allow blue to pass through blue and red to pass through red? The teleporters end in a neutrally-accessible place and would cause problems if the other team could get through.
I hope I was clear with this issue, thanks!
using UnityEngine;
public class Teleporter : MonoBehaviour
{
public bool teleported = false;
public Teleporter destination;
void OnTriggerEnter(Collider c)
{
if (c.CompareTag("BlueTeam"))
{
if (!teleported)
{
destination.teleported = true;
c.gameObject.transform.position = destination.gameObject.transform.position;
}
}
}
void OnTriggerExit(Collider c)
{
if (c.CompareTag("BlueTeam"))
{
teleported = false;
}
}
}
Answer by Owen-Reynolds · Mar 12, 2014 at 10:17 PM
An obvious way would be to also tag the teleporters RedTeam or BlueTeam. Then have them say "if this player has the same tag as me."
Would look like, I think: if(c.tag == tag)
Or, give each teleporter public string color;
and hand-enter "red" or "blue". Still same idea of telling the teleporters which team they are on. Then check with if(color=="red" && c.CompareTag("RedTeam") || color=="blue" && c.CompareTag("BlueTeam"))
.
Your answer
![](https://koobas.hobune.stream/wayback/20220613140109im_/https://answers.unity.com/themes/thub/images/avi.jpg)