Access a variable across all other players (online multiplayer).

Hey all,

So I’m hoping someone will be able to help me out with this. I’m using the Photon Unity Network and am setting up an online mutliplayer FPS game. It’s going well so far but I hit a snag.

Basically, I want to have enemy players have no highlight until they go in my crosshair, then they highlight red. This part is already working. The part I’m struggling with is, I want all teammate players to highlight with a blue color at all times.

I have a teamID variable set up on each player that spawns in. Is there a way for me to check every player’s teamID and compare them to my own teamID? I would only do this every time a new player joins the game or when a player switches teams. so it shouldn’t be too resource intensive to just check all players every now and then.

Any ideas on this? Does Photon have a built in command I’m not aware of that can do this simply?



foreach(PhotonPlayer pl in PhotonNetwork.playerList){

//compare teamID (maybe something like this:

   if(pl.gameObject.getComponent<yourscrioptwithteamID>().teamID=teamID(this time your own)){

//do stuff



I hope you got the idea.