Hello everybody!
So the problem is the first player who connects sees the weapon of second connected player, but the second player doesn’t see first connected player’s weapon.
Should I make after connecting to the server, get every player’s weapon and display them on current player’s display? I mean syncing.
You haven’t’ posted where CmdChangeWeapon gets called, or if RpcChangeWeapon is only ever called from that command. I’m going to assume that you are calling CmdChangeWeapon when a new player is created. If that is the case then later players will never see the weapons of earlier players, since RPC’s are not cached. Only clients that are connected at the time the RPC is called will receive it.
You could change your system so it works off of a syncvar and runs out of start so all newly connecting players will know what weapon to setup, or you could call the RPC every time a new player connects.
It gets called in void Start(){}, once player connects to the server.
I really like the second option (new player connects), is in NetworkBehaviour any function to check if a new player is connected?
Anyway, I am going to check about SyncVar in reference.
Thanks for helping!
I believe there is a networkserver or network manager callback available, but I usually just use Start in the Player object, since you generally want to make sure the new Player object has been instantiated/spawned before you start sending out further instructions to the client anyways.
So I just added the function to showMyWeapon() to the player object and once someone connects to the server, the server calls this functions from the localplayer as RPC. Thanks for clarifying, now everything is working.