Hello Title was too general but I have several problems in my mind. I am new at UnityNetworking. I am watching youtube tutorial from quill18 and trying to implement on my project. So I know [SyncVar] values can only set and sync in server. But even I check isServer > hasAuthority > isLocalPlayer I cant be able to sync them properly. I can only be able to sync them only and only under isServer. Here is problem begins..
- So I have two public int variables with [SyncVar] and I am checking their values from Unity3D if they changed.
- If I change them under isServer if statement, they are changing both in Server and Client to 100 and 100.
- But after this If I change them in hasAuthority if statement they wont change same goes for isLocalPlayer...
- I tried changing them in a function before checking if isServer doesnt work.
- Even I try [Command] function, I know it runs in Server values still didn't change.
my code
private void Update()
{
ServerUpdate();
ClientUpdate();
}
[SyncVar] public int syncIT_1;
[SyncVar] public int syncIT_2;
void WillItSyncNow()
{
if (isServer)
{
syncIT_1 = 300;
syncIT_2 = 300;
}
}
[Command]
void CmdSyncPlease()
{
syncIT_1 = 400;
syncIT_2 = 400;
}
void ServerUpdate()
{
if (isServer)
{
syncIT_1 = 100;
syncIT_2 = 100;
if (hasAuthority)
{
syncIT_1 = 200;
syncIT_2 = 200;
if (isLocalPlayer == true)
{
WillItSyncNow();
CmdSyncPlease();
}
}
}
}
My Server Client Latest Values:
My Client Latest Values: