0

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:

enter image description here

My Client Latest Values:

enter image description here

derHugo
  • 83,094
  • 9
  • 75
  • 115
BGK
  • 1
  • what does `ClientUpdate` do? – derHugo Feb 11 '19 at 09:47
  • It is empty for now. But later I want to check ifServer then return and TurnTimer if equals 0 then EndTurn for client side.. – BGK Feb 11 '19 at 13:14
  • The main problem here: I can Sync Values under first isServer control from ServerUpdate like syncIT_1 = 100; and then both clients and server got value of 100. But when I do like syncIT_1 = Random.Range(1, 100); both client and server get different values which I really want to know why. Isn't suppose to sync values from server side?. – BGK Feb 11 '19 at 13:24

0 Answers0