Hi,
So i am new to UNET, and i have been battling arround the web for the whole week searching for information on how to properly syncronize structures. I am currently working on a college project that involves creating a multyplayer game, and what happens is that my whole game works arround a structure that stores the information of every grid position of my board game, and i need to get that syncrozined for all the clients.
public struct Quadricula {
public Vector3 position;
public bool isSpawn;
public bool isOpen;
public bool isWall;
public bool hasBox;
public bool hasBomb;
public bool onFire;
public GameObject obj;
}
public class SyncListQuadricula : SyncListStruct<Quadricula>{}
public class GameManager : NetworkBehaviour {
public SyncListQuadricula m_labirinto = new SyncListQuadricula ();
//More Variables here
void Start () {
labirinto = new Quadricula[rows, cols];
// Gerar Labirinto
SetLabirinto ();
if (isServer) {
SetCaixas ();
}
}
//SetLabirinto()
private void SetCaixas () {
int placedBoxes = 0;
while (placedBoxes != numBoxes) {
for (int z = 0; z < rows; z++) {
for (int x = 0; x < cols; x++) {
if (!labirinto [z, x].isWall && !labirinto [z, x].isSpawn && !labirinto [z, x].isOpen && !labirinto[z,x].hasBox) {
int random = Random.Range (0, 3);
if (random == 1 && placedBoxes != numBoxes) {
GameObject box = Instantiate (destructableBox, labirinto [z, x].position, Quaternion.identity, destructablesHolder);
labirinto [z, x].hasBox = true;
labirinto [z, x].obj = box;
placedBoxes++;
NetworkServer.Spawn (box);
} else {
labirinto [z, x].hasBox = false;
}
}
}
}
}
}
ok, so, here is the problem, the player checks this structure to see if the position is clear and if he can walk to that position, if it has a box the player doesn’t move… if the structure doens’t syncronize the client will have no way of knowing, he will just move across the boxes…
i was sorta able to do this trought a ClientRpc function, but it was unstabble and it didn’t worked quite well…
Can anyone give me a hint on how to properly syncronize this structure? I houlp be so gratefull, this is wrecking my head !