Im New to networking and Unity as well, so if this is a simple mistake pls bear with me. Im working on a 2d multiplayer project. I have this NetworkBehaviour
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class LocalPlayerSetup : NetworkBehaviour {
void FixedUpdate(){
flipClients(netFacingRight);
}
void flipClients(bool facing){
if (!isLocalPlayer) {
netFacingRight = facing;
if (netFacingRight)
{
Vector3 flipSprite = this.transform.localScale;
flipSprite.x = 1;
transform.localScale = flipSprite;
}
else
{
Vector3 flipSprite = this.transform.localScale;
flipSprite.x = -1;
transform.localScale = flipSprite;
}
}
}
[SyncVar(hook = "CmdFlipSprite")]
public bool netFacingRight = true;
[Command]
public void CmdFlipSprite(bool facing)
{
netFacingRight = facing;
if (netFacingRight)
{
Vector3 flipSprite = this.transform.localScale;
flipSprite.x = 1;
this.transform.localScale = flipSprite;
}
else
{
Vector3 flipSprite = this.transform.localScale;
flipSprite.x = -1;
this.transform.localScale = flipSprite;
}
}
void Start () {
if (isLocalPlayer) {
GetComponent<PlayerManager>().enabled = true;
}
}
}
My problem is that, in the Client app, the host’s sprite is not flipping. In the Host i can see everything is working well.
Here is the part of PlayerManager where i call CmdFlipSprite()
facingright is Initially true.
void Update (){
MovePlayer (speedX);
if (facingright && speedX < 0 || !facingright && speedX > 0) {
facingright = !facingright;
flip();
local.CmdFlipSprite(facingright);
}
}
Hope that someone can help me. Thanks!