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 Z2CSharp · Jan 07, 2015 at 10:39 PM · networkingnetworkonlinehowplayer-settings

How to set the player number in a network game?

Hello,

I'm creating a game that involves playing over the network. However, I am stuck on an issue regarding how to determine which player is player one or two. The way the players meet online is through matchmaking (server pairs up players randomly). How would I be able to set a variable known as playerNumber once a match has been made? Thanks!

Comment
Add comment · Show 2
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 marshall50 · Jan 08, 2015 at 01:01 AM 1
Share

If server pairs up players randomly, set the numbers randomly too.. If I understood your question, you are making game for a limited number of players in game.. If it's so, there should be a maximum number of players in scene or in game, so set them gradually as they connect or randomly, just make sure that every player has it's own numer..

avatar image Z2CSharp · Jan 08, 2015 at 01:36 AM 0
Share

Ok, thanks! I will have it so that once the amount of players are met I will set their playerNumber into the order they connected.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Noah Dyer · Jan 08, 2015 at 01:56 AM

You may want to combine this logic with other gamestate issues, but here's an example dealing only with your specific question regarding player number.

  1. Create an empty gameobject called something like PlayerNumberManager, or something similar

  2. Create a Script on the object, call it something like PlayerNumberManagerScript.

  3. In the script create an int called playerNumber. You can leave it at null, or initialize to 0 or whatever suits your purposes.

  4. Create a function called something like GetPlayerNumberFromServer(). That function should ask the server what player it considers you to be, and sets playerNumber accordingly.

  5. Call GetPlayerNumberFromServer() when the appropriate condition is met.

  6. Reference playerNumber where relevant.

If playerNumber is going to be referenced by other scripts, it has to be public. If you want to trigger GetPlayerNumberFromServer() from another script, it will need to be public.

You might also consider doing additional work to make PlayerNumberManagerScript a singleton class, if you're worried about someone creating a second object and attaching a PlayerNumberManagerScript.

Comment
Add comment · Show 2 · 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 Z2CSharp · Jan 08, 2015 at 11:30 AM 0
Share

Thanks for breaking it down. I'm new to the whole network program$$anonymous$$g side of unity. I know how to code, I've just been wondering how to accomplish this task for a little while. Thanks a lot!

avatar image Noah Dyer · Jan 08, 2015 at 06:04 PM 0
Share

Good luck!

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

27 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 avatar image avatar image avatar image avatar image

Related Questions

Unity Photon Virtual Joystick Problem HELP???? 1 Answer

send message by networking 0 Answers

Multiplayer Game Disconnects 1 Answer

How can I create a simple chat system for my multiplayer game? 1 Answer

Online Rpg Animation does not work 0 Answers


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