Search Unity

Syncing Usernames (Textmeshes) over the network?

Discussion in 'Multiplayer' started by woodsynzl, Nov 12, 2015.

  1. woodsynzl

    woodsynzl

    Joined:
    Apr 8, 2015
    Posts:
    156
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.Networking;
    4.  
    5. public class PlayerName : NetworkBehaviour
    6. {
    7.     [SyncVar]
    8.     public string playerCurrentName;
    9.     public TextMesh playerNameMesh;
    10.  
    11.     void Update()
    12.     {
    13.         if (!isServer)
    14.             return;
    15.  
    16.         playerNameMesh.text = playerCurrentName;
    17.  
    18.         GetComponent<Transform>().name = playerCurrentName;
    19.     }
    20. }
    21.  
    Nothing really shows up on the client side, but the host sees everything
     
  2. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,533
    17min onwards pretty much goes through exactly what you're trying to do...


    really is disappointing there are so few tutorials on unet.
     
  3. woodsynzl

    woodsynzl

    Joined:
    Apr 8, 2015
    Posts:
    156
    Wow thank you so much! I'm working on using the new UI now.

    I'll share the script when I'm done
     
  4. Sewmina7

    Sewmina7

    Joined:
    Apr 17, 2018
    Posts:
    6

    about this video, It sends the command to server to change the username when hit change button, There is an issue with it in practical use, Let's say we are making some sort of game that all players spawns in a single scene, and we have to show some player data above all player's heads,If we use this method, and we spawn in this scene after 2, 3 players, how to let those players connected before me send the player data ?