network GUI not working

I'm trying to make an online fps game but the health bar is giving me the health of whoever I'm shooting at instead of my own player.

Part of my health code

function ApplyDamage (damage : float) {
    // We already have less than 0 hitpoints, maybe we got killed already?
    if (hitPoints <= 0.0)
        return;

    hitPoints -= damage;
    Healthtext = hitPoints.ToString();
    if (hitPoints <= 0.0)
    {
        Detonate();
    }
}

function OnGUI ()
{
  if (networkView.isMine) 
  {
    GUI.skin.font = MyFont;
    GUI.Label(Rect (135,506,900,900), Healthtext);
    }
}

Can you add the variable declaration of hitPoints and Healthtext? My guess is that's declared as static.. but it's just a guess. Also make sure that every player owns his own playerobject (everyone instantiate his own player). Some more information would be nice. If you check the health of all players in the inspector during game, are they set to the right values? Maybe add some Debug.Log messages to see when, who and on which player ApplyDamage is executed. With that little information i can't figure out any errors right now.

1 Answer

1

Try this out:

GUI.Label(Rect (135,506,900,900), this.Healthtext);

Don't know if it will work, but it might.