I have two scripts, one with the SyncVar and another one changing it’s value with a [command].
The problem is it will only show on the host.
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using System.Collections;
public class Enemie : NetworkBehaviour {
[SyncVar] public int health = 100;
void Update(){
GameObject.Find("Health").GetComponent<Text>().text = health.ToString();
}
}
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using System.Collections;
public class Player_Movements : NetworkBehaviour {
public Enemie enemie;
void Start(){
enemie = GameObject.Find("Enemie").GetComponent<Enemie>();
}
void Update () {
if(isLocalPlayer){
if(Input.GetKeyDown(KeyCode.Space)){
CmdHealth(10);
}
}
}
[Command]
void CmdHealth (int dmg){
enemie.health -= dmg;
Debug.Log(enemie.health);
}
}
In the documentation they says that these variables will have their values sychronized from the server to clients in the game that are in the ready state.
Am i missing something?