- Home /
Question by
meminmamon · Nov 04, 2015 at 02:44 PM ·
networkingsynchronization
How to sync material change at runtime - unet ?
Hi I'm trying to sync a material change among players(clients) without any succes so far, the player's material have to change as soon as the player is spawned. Here my code:
public class playerMaterialSync : NetworkBehaviour {
[SyncVar]
private Material syncMaterial;
void Start () {
StartCoroutine (CoolDown (2.0f));
}
void ChangeMaterial(){
if (!isLocalPlayer) {
GetComponentInChildren<MeshRenderer>().material=syncMaterial;
}
}
[Command]
void CmdSendMaterialToServer(Material mat){
syncMaterial = mat;
}
[ClientCallback]
void TransmitMaterial(){
if (isLocalPlayer) {
CmdSendMaterialToServer(GetComponentInChildren<MeshRenderer>().material);
}
}
IEnumerator CoolDown(float waitTime){
yield return new WaitForSeconds (waitTime);
TransmitMaterial ();
ChangeMaterial ();
}
}
Comment
Best Answer
Answer by seanr · Nov 04, 2015 at 06:16 PM
You cannot put a SyncVar on a unity asset such as a Material. It needs to be supported type. See the list at:
http://docs.unity3d.com/Manual/UNetActions.html