• 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
Question by thornekey · Oct 16, 2015 at 08:06 AM · c#networkingplayermultiplayer-networkinginformation

Send information from one player to another. Unity Multiplayer

I have a player log in with credentials (user name and password), then once they are successfully logged in, other information fields on a script on their player object are filled by my database. I have made it so that if I click on a player a player information box pops up on my screen. I know how to fill the text boxes on the pop up, but how do I fill it with their information? I tried to use RPCs but that didn't work and I am fairly sure they are depreciated now...

Please help.

Comment

People who like this

0 Show 3
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 thornekey · Oct 19, 2015 at 04:12 AM 0
Share

bump.please help.

avatar image Addyarb · Oct 19, 2015 at 06:49 AM 0
Share

Where's the information being stored? Database? A component on the player? If it's in a component, you can simply access said player's component as long as the variables are public. If it's a database, what type of database? What script are you using to interface?

avatar image thornekey Addyarb · Oct 19, 2015 at 07:51 AM 0
Share

Its stored on the player on a script component. and yes, the variable is public. How do I access the information from their player component to appear on my gui text when i click them. Ive already got the text part set up, just need it to show as their info.

2 Replies

· Add your reply
  • Sort: 
avatar image

Answer by meat5000 · Oct 22, 2015 at 09:36 AM

Came across t$$anonymous$$s info

http://docs.unity3d.com/Manual/UNetMessages.html

Comment
thornekey

People who like this

1 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 thornekey · Oct 22, 2015 at 10:23 AM 0
Share

hi @meat5000, thanks! I was actually just reading up on that too! For your research (aswell) another interesting attribute is: http://docs.unity3d.com/ScriptReference/Networking.SyncVarAttribute.html

avatar image meat5000 ♦ thornekey · Oct 22, 2015 at 11:57 AM 0
Share

SyncVar is mega useful. Its what is used to communicate data between players, such as position and rotation of player characters.

In uJS you use @SyncVar

UNet Tutorials

avatar image

Answer by Addyarb · Oct 19, 2015 at 08:28 AM

If the information is stored on a component of the player, you can just use a raycasting setup to get that player's collider. So here's how it works in English:


Player A clicks on $$anonymous$$s screen w$$anonymous$$le $$anonymous$$s mouse is over Player B.


Player A fires a ray via script at Player B.


Player A's ray $$anonymous$$ts Player B with said ray, and $$anonymous$$s [Player A] script returns Player B's collider.


Player A's script converts the returned collider to the collider's gameObject, and then to a component.


Player A gets the component "TheOtherPlayerScript" and then accesses a public variable to populate text objects.



And in script....

 void Update () {
             GetSelection();
         }
         
         void GetSelection() {
             // Use Input.GetKeyDown() for single clicks
             if(Input.GetKeyDown(KeyCode.Mouse0)) 
             {
             Ray ray;
             RaycastHit $$anonymous$$t;
                 // Reset ray with new mouse position
                 ray = Camera.main.ScreenPointToRay(Input.mousePosition); 
                 if(Physics.Raycast(ray, out $$anonymous$$t)) {
                 TheOtherPlayerScript script = $$anonymous$$t.collider.gameObject.GetComponent<TheOtherPlayerScript>();
                 //Access the public variables from here and you're all set.
                 }
             }
         }

























Comment

People who like this

0 Show 7 · 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 Addyarb · Oct 19, 2015 at 10:25 AM 0
Share

Oh okay, well it's a pretty basic thing to access a public variable of another script - but maybe not so much with GUI.

So on line 15, we declared the script on the player we just hit as a temporary variable "script."

So lets say we have a text component that displays that player's name and health.

After line 15 we would write:

(and please replace these string references ASAP)

 Text enemyNameDisplay = GameObject.Find("EnemyNameDisplay").GetComponent<Text>();
 enemyNameDisplay.text = script.name; //Name is the public variable
 
 float enemyHealthImage = GameObject.Find("EnemyHealthImage").GetComponent<Image>();
 enemyHealthImage.fillAmount = script.health/100;
avatar image thornekey Addyarb · Oct 19, 2015 at 11:10 AM 0
Share

@addyarb yes this just got the local player's info.. not the networked players info. It seems that when a new player connects his info is lost and he takes the local players info or null everything.... how do i make it get the other player?

avatar image meat5000 ♦ thornekey · Oct 21, 2015 at 09:20 AM 0
Share

Place a Cmd function in the script that fires off the players actual info from his system rather than reading the local info that appears on your own machine.

Show more comments

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

39 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 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

Can I use Rpc Calls and Commands on the same object? 0 Answers

NetworkMatch creating match not being found when doing ListMatches 0 Answers

Unity's LLAPI for Raspberry Pi Server? 0 Answers

How do I set non-player object client authority? 0 Answers

Distribute terrain in zones 3 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