SyncVar on Server Object
I've got a player controller that sends a command to a land object owned by the server when clicked. The player's command changes a few bools on the land's script, which should then sync to all the clients, revealing fences that pop up on each border. However it's not syncing. Further, it appears that the command is only working on the client that IS the server. Which is frankly baffling.
This is the code on the player controller:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class PlayerController : NetworkBehaviour {
[Command]
public void CmdClaim(int oid, GameObject land)
{
//transform.GetComponent<MeshFilter>().mesh = till_block;
if (land.GetComponent<ground_control>().isClaimed == false)
{
land.GetComponent<ground_control>().n_status = true;
land.GetComponent<ground_control>().s_status = true;
land.GetComponent<ground_control>().e_status = true;
land.GetComponent<ground_control>().w_status = true;
}
}
Then on the land block, in the update, I've got four game objects that I set to active with the bools I sync. It works for the host, but not any client, nor does it update for the clients when the host claims a spot.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class ground_control : NetworkBehaviour {
public GameObject s_border;
public GameObject n_border;
public GameObject e_border;
public GameObject w_border;
[SyncVar]
public bool s_status = false;
[SyncVar]
public bool n_status = false;
[SyncVar]
public bool e_status = false;
[SyncVar]
public bool w_status = false;
void Start()
{
n_border = transform.Find("borders").transform.Find("n_border").gameObject;
s_border = transform.Find("borders").transform.Find("s_border").gameObject;
e_border = transform.Find("borders").transform.Find("e_border").gameObject;
w_border = transform.Find("borders").transform.Find("w_border").gameObject;
}
void Update()
{
n_border.SetActive(n_status);
s_border.SetActive(s_status);
e_border.SetActive(e_status);
w_border.SetActive(w_status);
}
The land object has a network id and is set to be server only, I'm also calling NetworkBehaviour on both. The player currently moves and animates correctly across clients and the server. It's just this server-side object I'm struggling with.
Help!