Hello, I need to “send” the player’s health on the network. I have already set up the network and can have other players join the network, but when a player is injured on one game it is not on the other. Thank You
1 Answer
1You should use RPC-Calls like this:
Part of the script attached to each player:
var health = 100;
function PlayerGetSInjured(damage:int){ //Function which gets called when a player gets injured
health = health-damage;
networkView.RPC("SyncHealth", RPCMode.All, health);
}
@RPC
function SyncHealth(healthSync:int){
health=healthSync
}
For this to work you need a networkView attached to the player.
Here is some more information on RPC’s http://docs.unity3d.com/Documentation/Components/net-RPCDetails.html
Hope it helps.
Thank you very much, Would the health variable still work locally? For exsample if i had several players could i just attach a script like this to all of them? Thanks
– MileSplitif you don't make it static every player would have his own health variable. So yes.
– ExTheSea