- Home /
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?
Thanks!
Answer by TCD · Jul 21, 2014 at 12:03 AM
(C#)
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.
Thanks for the help! There seems to be a problem though. PhotonPlayer does not pass a Game Object to pl. So doing pl.gameObject isn't working.
I feel like this is close though. We just have to figure out how to access the Game Object of pl.
I'll keep trying but if you happen to find a way please let me know! ^^
Hmmm your right i think there is no way to get the gameObject because a photonplayer is a instance of your game running (or something nearly maybe) and not your player Object ingame, so nobody knows which object which player is.
I am program$$anonymous$$g a $$anonymous$$ultiplayer shooter too and i give every players gameobject his own Photonnetwork.player.name so every Player object is uniqe. Hope this will help you if not i will be back tommorrow with more helpfull ideas.
PS:Plaese excuse my English and writing, because in germany its 1 o'clock at night right now.
Now each playObject has it own photonplayer name, i think you could do:
foreach(PhotonPlayer pl in PhotonNetwork.playerList){
if(GameObject.Find(pl.name).getComponent<yourscrioptwith$$anonymous$$mID>().$$anonymous$$mID=$$anonymous$$mID){
//finaly do stuff
}
}
Your answer
Follow this Question
Related Questions
Multiplayer updates are really slow 0 Answers
How to Debug in a standalone build? 4 Answers
Can you make a FPS multiplayer on a Android or iOS device? 1 Answer
Making my fps a multiplayer 0 Answers