- Home /
Syncvar Not Updating On Late Joining Clients
I have a problem with syncing clients using Mirror It doesn't have any problem with clients that are already joined together since it updates correctly, the problem occurs when a new player joins or an old player reconnects to the server.
public class PlayerCharacter : NetworkBehaviour { [SyncVar] public int curhp;
if "f" button is pressed it triggers CmdDealDamage (which works properly without any problems)
[Command] public void CmdDealDamage(int damage, string name) { RpcSendDamage(damage, name); }
[ClientRpc] void RpcSendDamage(int tempDamage, string name) { PlayerCharacter targetPC = GameObject.Find(name).GetComponent(); targetPC.TakeDamage(tempDamage); enemyHealth.SetEnemyHealth(tempHealth,targetPC.maxhp); }
void TakeDamage(int damageDealt) { curhp -= damageDealt-armor; } }
For instance he has 100 max hp, and during a combat with another player he takes 40 damage which should be leave him with 60 hp.
When a new player joins all he sees is 100/100 instead of 60/100, in the inspector of the new client curhp also shows 100
the curhp on both first 2 clients shows 60 on curhp.
Please help
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Custom network ID values 0 Answers
Network View ID Allocation 1 Answer
Best way to choose Google Play Realtime Multiplayer Host? 0 Answers