Search Unity

Enemy / friend bar

Discussion in 'Multiplayer' started by TomPo, Jul 5, 2015.

  1. TomPo

    TomPo

    Joined:
    Nov 30, 2013
    Posts:
    86
    Hi.
    'Small' problem:

    Code (csharp):
    1.  
    2. GameObject OthersBar;
    3. public int myTeam; //- may be a string or enum - int just for easy testing
    4.  
    5.     void Start () {
    6.         if (m_PhotonView.isMine == true) {
    7.             createPlayerGUI ();
    8.         }
    9.         else{
    10.             createOthersBar ();
    11.         }
    12.     }
    13.  
    14.     void createOthersBar (){
    15.         OthersBar = (GameObject) Instantiate(OthersBar_prefab, new Vector2(0,0), Quaternion.identity);
    16.         OthersBar.GetComponent<OthersBar_scr> ().HP = PlayerHP;
    17.         OthersBar.GetComponent<OthersBar_scr> ().Name = PlayerName;
    18.         if(myTeam == ????? Problem ?????) {
    19.               OthersBar.GetComponent<OthersBar_scr> ().Relation = "friend";
    20.         }
    21.         else{
    22.               OthersBar.GetComponent<OthersBar_scr> ().Relation = "enemy";
    23.        }
    24.     }
    25.  
    26.  
    Problem - how to check if our team is the same as the m_PhotonView.Owner we are currently in?

    Sure, easy way is to set if myTeam == 1 then bar color red
    but then it will looks stupid when our whole team will have f.e. red color because we are part of red team and enemys will have green bars.
     
    Last edited: Jul 5, 2015
  2. TomPo

    TomPo

    Joined:
    Nov 30, 2013
    Posts:
    86
    SOLVED :)

    in CreateOthersBar added function foreach gameobject player with tag player
    and two statements
    if player id != PlayerID - create bar
    if player.team != myTeam - status enemy else friend

    hope this helps someone