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 Jotin · Jun 21, 2015 at 07:07 AM · multiplayerplayerclassescombatstats

How to differentiate between players in multiplayer game

So I am trying to make a multiplayer game, and the thing is how do I identify one player and another one. What I mean is I have a class with the player stats, such as health and attack for now. I spawn the player when they are connected to the server with a player prefab (just a cube with movement, and the stats). I'm trying so if a player right clicks it'll just do damage to anyone in front of it one time just for testing purposes. I do not know how to go to that specific player's class and say doDamage() to the other person and how i get the other person's specific stats. I just need a small example of how to do this thanks a lot!

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
2

Answer by Em3rgency · Jun 21, 2015 at 07:16 AM

Keep in mind that multiplayer games are significantly harder to make than single player games. I suggest you learn how to do something in single mode before trying to tackle it in multiplayer.

Now as for your problem. You don't need to specify a player in code, when doing things just with that player. So for example if I had a LevelUp() function, and I called it for an object, unity would automatically only level up the specific player object that called it, not all the players. No additional handling needed.

Now when doing things like damaging other objects, you will get the object reference when checking if you hit something. For example, if you want to hit something in front of you, you will probably perform a raycast (look it up) to see if there is anything in front. And the raycast WILL return the object it hits, so you can call TakeDamage(amount) or whatever on that object.

Once again, doing this in multiplayer will be harder, as you will have to add in an additional layer of code, to handle the information exchange between the server and clients. And it also depends on what kind of networking setup you will be going for. Server authoritative code would look different from client trust (client authoritative? Don't know what the term is) code.

Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiplayer problem - 2nd player erratic movment? 0 Answers

How to make multiplayer editor/race 0 Answers

How to check which gameobject is the player using 2 Answers

unity game 1 Answer

[Multiplayer]How to individualize the Player 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