- Home /
Have an Int be in a Network Noob Networking Question
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
Answer by ExTheSea · Apr 26, 2013 at 05:35 PM
You 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
if you don't make it static every player would have his own health variable. So yes.
Your answer
Follow this Question
Related Questions
How to retrieve current stock market prices? 2 Answers
OnGUI not recognizing variable change 1 Answer
Do static variables carry values between Clients? 1 Answer
Two questions with mutliplayer 0 Answers