Search Unity

Sync Scale over Unet?

Discussion in 'UNet' started by wwm0nkey, Oct 22, 2015.

  1. wwm0nkey

    wwm0nkey

    Joined:
    Jul 7, 2015
    Posts:
    42
    How would I go about doing this? Doesn't seem to be an option which I find a bit odd?
     
  2. Chom1czek

    Chom1czek

    Joined:
    Sep 19, 2015
    Posts:
    66
    I just noticed it as well. Now I have to [SyncVar] it :X
     
  3. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Current NetworkTransform doesn't sync scales IIRC, I'd go for a simple custom script with SyncVars if it's true..
     
  4. Ben-Sampson

    Ben-Sampson

    Joined:
    Nov 5, 2014
    Posts:
    10
    I've been trying to use a custom script to sync localscale.
    I don't know why it's not working, any help?

    [SyncVar]
    private Vector3 syncScale;

    [SerializeField]
    private float enlargeAmount = 0.05f;

    void Update()
    {
    if (isLocalPlayer)
    {
    if(Input.GetKeyDown(KeyCode.Space))
    {
    Enlarge();
    }
    }
    }

    public void Enlarge ()
    {
    if (isLocalPlayer)
    {
    transform.localScale += new Vector3(enlargeAmount, enlargeAmount, 0);
    }
    TransmitScale();
    SyncScale();
    }

    void SyncScale()
    {
    if (!isLocalPlayer)
    {
    transform.localScale = syncScale;
    }
    }

    [Command]
    void CmdProvideScaleToServer(Vector3 scale)
    {
    syncScale = scale;
    }

    [ClientCallback]
    void TransmitScale()
    {
    if (isLocalPlayer)
    {
    CmdProvideScaleToServer(transform.localScale);
    }
    }
     
  5. CStampGames

    CStampGames

    Joined:
    May 16, 2017
    Posts:
    4
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Just SyncVar a vector3 and use a SyncVar hook to set the actual scale from that value.