Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Fikule · Jan 06, 2017 at 10:20 AM · networkingmultiplayeritweenclick objects

Get the Player that Clicked an Object in Multiplayer?

So, I'm using IPointerClickHandler on an object

  public void OnPointerClick(PointerEventData eventData) // 3
  {
      Debug.Log("Click!");
  }

This is a multiplayer game, so each play has a Player character. What would be the best way to get the player character that clicks an object? I'm hoping not to have global variables to do this.

Essentially each player has a tooltip that I want to populate with information on things they click.

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 LK84 · Jan 06, 2017 at 10:38 AM

If every Player has localAuthority you can use NetworkInstanceId https://docs.unity3d.com/ScriptReference/Networking.NetworkInstanceId.html. (I assume the script with the method OnPointerClick is a NetworkBehaviour

   public void OnPointerClick(PointerEventData eventData) // 3
   {
       CmdSendClickToServer(netId)
   }
 
 [Command]
 void CmdSendClickToServer(NetworkInstanceId Id)
 {
      //I assume you have created a class called Player:
      Player clickingPlayer= NetworkServer.FindLocalObject(Id).GetComponent<Player>();
     
 }

If you want to know the clicking Client directly you can also look into https://docs.unity3d.com/ScriptReference/Networking.NetworkConnection-connectionId.html. But if each Player has localAuthority, that would be redundant.

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 MarekRimal · Feb 04, 2021 at 10:44 AM 0
Share

Trying to send command for object without authority

avatar image
0

Answer by pfnienow69 · May 27, 2020 at 12:18 PM

(Unity) I have a similar problem, but it is in a local structure, using the new Input System and the MultiplayerEventSystem. I have 4 players and they all have the same buttons for selection (in this case the same Root). How do I identify the player who pressed the button (OnClick)? I don't know what kind of return parameter to ask to be able to link to the player who made the click action. If possible, could you briefly demonstrate a script? Thank you!

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

7 People are following this question.

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

Related Questions

Unity networking tutorial? 6 Answers

How can a client connect more players to a network game? 1 Answer

Can I add a network prefab at runtime? 1 Answer

UNET Players are movable on collision 2 Answers

Problems with Scene Change networking Unet 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