Hi all,
i have a cube that is interactive, so when you press right button on it, a syncvar bool will be true if false or false if was true
so the code of cube is:
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class Netonoffswitch : NetworkBehaviour {
[SyncVar] public bool SwitchedOn = false;
public void CmdSwitchOnOff(bool SwitchedOn2){
Test (SwitchedOn2);
}
[Command]
private void CmdTest(bool swichedon2){
SwitchedOn = swichedon2;
}
[ClientCallback]
private void Test(bool swichedon2){
CmdTest (swichedon2);
}
}
and the code of localplayer is:
void Update(){
if(Input.GetKeyUp(KeyCode.Mouse1)){
if (hit.collider.name == "on_off_switch") {
hit.collider.gameObject.GetComponent<Netonoffswitch>().CmdSwitchOnOff((hit.collider.gameObject.GetComponent<Netonoffswitch>().SwitchedOn ? false : true));
}
}
}
it work fine from server to client, but it doesnt work from client to server. any help is appreciated.