- Home /
Synchronize different prefab material over the network?
I am currently running into the following noob question while using the uNet-networking system: I have a player model prefab which is setup all right and I have a material selection menu where the players can choose their favorite color, let's say REDmetal or BLUEmetal and a default GREENmetal. I get it so far that the local player works fine. everyone chooses his/her material and sees his own player in the right color in the network scene, BUT ALL THE OTHER PLAYERS REMAIN THE DEFAULT GREENmetal... I have tried [SyncVar] and [Command], [ClientRpc]-stuff, but nothing really helpes. The material is never synchronized for the view of other players.
I am really new to networking and struggling since days. Hope for help here :)
[SerializeField]
private Material ShipMat_one;
[SerializeField]
private Material ShipMat_two;
[SerializeField]
private Material ShipMat_three;
[SerializeField]
private Material ShipMat_four;
[SerializeField]
private Material ShipMat_enemy;
[SerializeField]
private Material WingMat_one;
[SerializeField]
private Material WingMat_two;
[SerializeField]
private Material WingMat_three;
[SerializeField]
private Material WingMat_four;
[SerializeField]
private Material WingMat_enemy;
[SyncVar]
public GameObject Ship;
[SyncVar]
public GameObject Wings;
void Update()
{
ApplyMaterial ();
}
void ApplyMaterial()
{
if (isLocalPlayer)
{
if (CharacterSelecter.selectionIndex == 0)
{
Ship.GetComponent<Renderer> ().material = ShipMat_one;
Wings.GetComponent<Renderer> ().material = WingMat_one;
}
if (CharacterSelecter.selectionIndex == 1)
{
Ship.GetComponent<Renderer> ().material = ShipMat_two;
Wings.GetComponent<Renderer> ().material = WingMat_two;
}
if (CharacterSelecter.selectionIndex == 2)
{
Ship.GetComponent<Renderer> ().material = ShipMat_three;
Wings.GetComponent<Renderer> ().material = WingMat_three;
}
if (CharacterSelecter.selectionIndex == 3)
{
Ship.GetComponent<Renderer> ().material= ShipMat_four;
Wings.GetComponent<Renderer> ().material = WingMat_four;
}
}
//this is just a possible solution for a default enemy-material
/*
if (!isLocalPlayer)
{
Ship.GetComponent<Renderer> ().material = ShipMat_enemy;
Wings.GetComponent<Renderer> ().material = WingMat_enemy;
}*/
}
}
I also tried to use a $$anonymous$$aterial ans use it as a [SyncVar], but it did not synchronize through the network :-/