- Home /
Question by
Tschlompf · Jan 26, 2018 at 10:46 PM ·
c#scripting problemspriteserver
Help me understand SyncVars please
So, I'm basically trying to sync when a player flips his character. But what happens on the client side is that nobody flips and on the host side the player from the client goes completely crazy and flips endlessly left/right/left/right. I think I don't understand the thing with the SyncVar and hook fully:
[SyncVar(hook = "CmdFlip")]
public bool m_FacingRight = true;
[Command]
private void CmdFlip (bool _m_FacingRight)
{
m_FacingRight = _m_FacingRight;
m_FacingRight = !m_FacingRight;
if (m_FacingRight) {
gameObject.GetComponent<SpriteRenderer>().flipX = false;
gameObject.GetComponent<PolygonCollider2D>().offset = new Vector2(0, 0);
}
if (!m_FacingRight) {
gameObject.GetComponent<SpriteRenderer>().flipX = true;
gameObject.GetComponent<PolygonCollider2D>().offset = new Vector2(0.4f, 0);
}
}
Comment