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
1
Question by Chapi · Oct 22, 2014 at 08:57 PM · networkingnetworkplayer

Find gameobject by Networkplayer?

On the server side of my game I have a player.cs script attached to every playerprefab on the scene. What I need is to get the player script on the gameobject owned by a specific networkplayer.

The reason I'm using networkplayer is because this happens OnPlayerDisconnected(NetworkPlayer)

So how am I supposed to do this? Oh and one more lil thing, are viewIDs unique per player or per gameobject? If one player owns two gameobjects, do they have same viewID?

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

2 Replies

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

Answer by Anxo · Oct 22, 2014 at 09:09 PM

Actually, disregard my last answer, what is much eaiser is to just associate the Networkplayer with a player gameobject when they connect to the server,

 OnPlayerConnected(Networkplayer playerNP){
   // here you instantiate your player right? Add them to a List and add the networkplayer to a list as well, that way the int ids both
 }


Then you just get the int on disconnect with

 int disconnectedPlayerID = NetworkPlayerList.IndexOf(NetworkPlayerDisconnecting);
 Destroy(PlayersList[disconnectedPlayerID]);

WUCC

Comment
Add comment · Show 1 · 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 Chapi · Oct 22, 2014 at 09:27 PM 0
Share

Yeah after I posted this I kept on searching and apparently there's no other way or no unity method for doing this so I started doing what you suggested already hah. Thanks thought, I didn't want to have to deal with arrays tho :(

avatar image
0

Answer by 03gramat · Jan 15, 2015 at 02:18 PM

viewId's are unique to the object but should match across all clients. That viewID is owned by the NetworkPlayer that created it (or re-set it's ID) but it's best to have all viewID's owned by the server and have the clients just know what objects they are allowed to control, Here's a tutorial that might help:

https://www.youtube.com/watch?v=QfzrpxO89tU

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Network two players collision 2 Answers

UNET Networking: where and when to initialize instantiated player on the client? 0 Answers

After 10 Seconds Player Spawning in Multiplayer 0 Answers

How do I store input of another player over the network? 1 Answer

how TargetRpc works 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