Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

UNET Issue. I want to send a string to appear in a Text object on another screen

Discussion in 'UNet' started by TheAMD, Apr 25, 2017.

  1. TheAMD

    TheAMD

    Joined:
    Apr 27, 2016
    Posts:
    2
    Hi guys;
    I'm working on a messaging system that I WANT to send a string array over a network to an identical client on the same network and show the text in a text box.

    The player presses buttons which set the element to a certain word, then increase along the array (Until all are full, or send is pressed). When it is full, I want to press the send button, and the 'other text box' on the other client have the message appear into it.

    I've got NetworkManager and NetworkHUD, with an Online and offline scene but.. I can't do any more.

    Any ways to 'send' this string array?
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    A few ways to do this.

    1) On Client 1, run a Command when the send button is pressed, which includes the string as a parameter. The Command either updates a Syncvar or runs a ClientRPC which Client2 receives. Client2 then updates the text box with the received string.

    https://docs.unity3d.com/Manual/UNetActions.html
    https://docs.unity3d.com/Manual/UNetStateSync.html

    2) On Client1 send a Message to the server which includes the string when the send button is pressed. When the server receives the string, the server sends a message to Client2 again including the string. When Client2 receives the string it updates the text box with the contents. (This is the way I would do it)

    https://docs.unity3d.com/Manual/UNetMessages.html
     
  3. TheAMD

    TheAMD

    Joined:
    Apr 27, 2016
    Posts:
    2
    Thanks mate!
    I appreciate the time, my next step is finding a way to decide what will be the client and server, and how to specify!
    Sure, its linked to the NetworkHUD somehow.