- Home /
How to sync variables with UNET
Hello guys, I'd like to know how to syncronize variables between objects using UNet. Thank you.
Answer by hexagonius · Jan 02, 2018 at 08:45 PM
Thank you. But if I change the variable on the clients the variable won't be synchronized in the server because the SyncVar syncs server variables with client variables... Is there a way to make it possible? Thanks.
The client needs authority and needs to send a command to the server who then can alter the variable.
How can i assign authority to a client? I tried using:
if (isServer){ GameObject[] gos = GameObject.FindGameObjectsWithTag("Player"); foreach(GameObject go in gos){
if (go.GetInstanceID() != gameObject.GetInstanceID){
go.GetComponent().AssignClientAuthority(GetComponent().connectionToClient); } }
}
Answer by alottadumspam · Mar 17, 2019 at 02:45 AM
This might work. If possible could you give a more specific problem, or what kind of information you are trying to send. https://docs.unity3d.com/ScriptReference/Networking.PlayerConnection.PlayerConnection.Send.html