Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by drex150 · Jul 20, 2014 at 11:10 PM · multiplayerfpsshootercolorsteam

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image drex150 · Jul 21, 2014 at 12:33 AM 0
Share

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! ^^

avatar image TCD · Jul 21, 2014 at 10:50 PM 0
Share

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.

avatar image TCD · Jul 22, 2014 at 09:29 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

How to make a camera work in this circumstance. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges