Search Unity

Third Party Unity / Photon - Displaying player names above their head

Discussion in 'Multiplayer' started by GSZ, Oct 7, 2014.

  1. GSZ

    GSZ

    Joined:
    Dec 13, 2012
    Posts:
    11
    I'm trying to display each players name above their head. I originally had it displayed with GUI text, but didn't like that the name displayed even when the character wasn't visible (behind a wall for example).

    Does anybody know how to make it so the name will only display if the player itself is fully visible? Was thinking of using a 3D Text object, but can't figure out how to make it so each players name goes into the text field, or how to make it so the the text box always faces whichever player is looking at it.

    Thanks.
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    In the PUN package is a "ShowInfoOfPlayer" script. Take a look.
    If I remember correctly, it uses 3d Text.
    You will need to make it visible/invisible based on a raycast between players.
     
  3. rob5300

    rob5300

    Joined:
    Aug 3, 2014
    Posts:
    8
    If you want this functionality, you can have a 3D text game object where ever you wish it to be (over the players head for example) and have a script attached to ether the root of the player with the networkview or that object that checks if this is our player or a mirrored one (soo someone else) and to enable it, set the players name as the text string for the object and make sure its rotation is set to look at the player.
    Example code:
    Code (CSharp):
    1.     void Start(){
    2.         if(networkView.isMine){
    3.             //Set up various items todo with the player, such as the Name!
    4.             PlayerName = PlayerPrefs.GetString("playername");
    5.             GetComponentInChildren<TypogenicText>().Text = PlayerName; //Can also just use GetComponent
    6.             //I recommend this for 3d world text, typogenic as used above: https://www.assetstore.unity3d.com/en/#!/content/19182
    7.         }
    8.     }
    http://wiki.unity3d.com/index.php/LookAtCameraYonly Use this to make the object look at the camera, may need modifying.

    As for rendering when only fully visible, maybe set it to only display when at a certain distance from the other player, or have points on the player and checking if all are being rendered using OnBecameVisible()?