- Home /
OnSerializeNetworkView problems with clients
Hello everyone.
Its the first time i use this function and i have a little problem with it. i want to display the health/maxhealth if the player aims at another player.
At the moment if there is only 1 client connected to the server all runs well but if a second client is connected all players have the health/maxhealth from the server displayed.
function OnSerializeNetworkView(stream : BitStream, info : NetworkMessageInfo)
{
health = PlayerPrefs.GetInt("Health");
maxhealth = PlayerPrefs.GetInt("Max Health");
if (stream.isWriting)
{
stream.Serialize(health);
stream.Serialize(maxhealth);
}
else
{
stream.Serialize(health);
stream.Serialize(maxhealth);
}
}
And this is are the lines to change the value for the display
healthText = hit.transform.GetComponent(PlayerLocalVars).health;
maxhealthText = hit.transform.GetComponent(PlayerLocalVars).maxhealth;
Some info:
The script "PlayerLocalVars" is attached to the player. The script "PlayerLocalVars" got the Network View component. The server is a player aswell.
Answer by Maroku · Apr 20, 2013 at 12:14 PM
Problem solved!
i got rid of the OnSerializeNetworkView and used an RPC call.
everytime the health change (regeneration or damage by npcs) i call this RPC
networkView.RPC("SetHealth", RPCMode.AllBuffered, PlayerPrefs.GetInt("Health"), PlayerPrefs.GetInt("Max Health"), gameObject.networkView.viewID);
and the function does this
@RPC
function SetHealth(playerHealth : int, playerMaxHealth : int, viewID : NetworkViewID)
{
health = playerHealth;
maxhealth = playerMaxHealth;
}
now it doesnt matter if you are server or client.. the health/maxhealth gets displayed correcty for each client and server.
Your answer
Follow this Question
Related Questions
How to watch in client applications what it is happening in the server one? 0 Answers
How to Sync a sprite change to other clients? 0 Answers
Is it possible to send whole bytearray at once? JS 0 Answers
Networking 0 Answers
Is there a way to notify to the app once client has connected to server? 2 Answers