Search Unity

Show the name of the other players in different color

Discussion in 'Multiplayer' started by jeff.fnd, Mar 28, 2014.

  1. jeff.fnd

    jeff.fnd

    Joined:
    Jul 31, 2013
    Posts:
    10
    Hi all. Please help me.

    I have a script that shows the names of the players over the head.

    But I wish all the players that are not on my team / color realm name is different from mine.

    So would check my kingdom, and compare with the realm of the other player, if different color name should be different.

    The script I am using is this very basic and only shows the name on the head.


    Code (csharp):
    1.  
    2. if (!photonView.isMine){
    3.  
    4.             GUI.color = Color.blue;
    5.  
    6.             screenPos = Camera.main.WorldToScreenPoint(target.position);
    7.             screenPos.y = Screen.height - screenPos.y;
    8.             screenPos.z = 0f;
    9.             GUI.Label(new Rect(screenPos.x-40,screenPos.y-55,100,20),"Nome: "+playerName);
    10.         }
    11.  

    Someone for mercy, could help me to implement?

    I thank you very much.
     
  2. jeff.fnd

    jeff.fnd

    Joined:
    Jul 31, 2013
    Posts:
    10
  3. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    You would need to keep track of which team each character is in, and check against it changing GUI.color if the character is on the opposing team.
     
  4. jeff.fnd

    jeff.fnd

    Joined:
    Jul 31, 2013
    Posts:
    10

    So, all players have a variable called "kingdom" that shows which team it is.

    What I'm not getting is precisely this comparison.

    How to compare my kingdom and the other player?

    Something like:

    if (!photonView.isMine MyTeam !​= YouTeam) {
    change the color ...
    }

    This does not work. = /
     
  5. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,124
    Well I never used pun so am not sure how do you make yourself owner of an object. the thing is that this script will run for all players so you should kinda detect the team of the player which is owned by you and put it's team name in a field in a manage script or static field (bad design) and then compared all others with that.
     
  6. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    In the updated PUN packages (v1.26 and up) you will find a demo for Pickup and Teams. It includes scripts that you should be able to re-use for your case. Take a look at the demo scene and the change log - both point out where to find relevant code.
    I created a C# "Extension Method" for PhotonPlayer to set and access the team per player easily. With that, you can easily set or compare the "Custom Property" which is used to store team per player.