Networking and Health question

Hello,

I’ve a question about how to show lifepoints from Client 1 in game of Client 2.

I send a RPC when I hit the other Player.

networkView.RPC("meleeRPC", uLink.RPCMode.Others, "test");

The function is doing this:

[RPC]
    void meleeRPC(string playerhit)
    {
        healthPoints-=10;
    }

Up to this it works well, the other Client is getting the Message that his lifepoints get -10.

Now I want to show both lifepoints on both clients.
The problem is that if I hit my enemy his lifepoints decrease on his screen but not on mine.

So this is how I show lifepoints:

public class lpManager : uLink.MonoBehaviour {


	public GUIText lpOne;
	public GUIText lpTwo; 
	private GUIText myLP;

	void Start () 
	{
		RPCTest.healthPoints = 100;
		lpOne = GameObject.FindWithTag("lpOne").GetComponent<GUIText>() as GUIText;
		lpTwo = GameObject.FindWithTag("lpTwo").GetComponent<GUIText>() as GUIText;		
		
		if(uLink.Network.player.ToString()=="Client 1")
        {
            myLP = lpOne;
        }
        if(uLink.Network.player.ToString()=="Client 2")
        {
            myLP = lpTwo;
        }
	}

	void Update () 
	{	
		myLP.text=RPCTest.healthPoints.ToString();
	}
}

My question is how do I show the enemy’s lifepoints on my screen?
I tried it with something like this but it doesnt work:

	if(uLink.Network.player.ToString()=="Client 1")
    {
		if(!networkView.isMine)
		{
			lpTwo.text=myLP.text;
		}
	}

I hope some of you can explain at which point I’m working wrong.

Thanks!

I don’t know much about uLink, but the simplest solution would be to define a health variable for each player and update them twice on the hit event, once via RPC and once locally. That way the values should be the same on both clients.

I don’t quite see why you’re trying to set lpTwo.text=myLP.text instead of getting something like lpTwo.text = RPCTest.healthPointsPlayer2.ToString();

Option 2: I don’t know how you register the hit, but if you use OnTriggerEnter you could actually just check for the hit on each client and decrement the health on each client. No network call needed at all, except for the player position synchronization which is needed in any case…

Hope this helps…