So what I want to do isn’t very complex and I hope it’s just some syntax or a small bit of understanding that I’m missing.
But basically I want to have my server generate a seed which all my clients are able to use to generate identical randomly generated levels (the server generates the seed randomly but each clients has the same seed essentially).
The way I implemented this was to have a gameObject (this object just exists locally in scene) with Network Identity which used a NetworkBehaviour script to check it it was the server and if it was it would generate a seed in the form of a string which was also a [SyncVar]. It would then use a cmd to sync the seed.
The code looks something like this:
[SyncVar]
public string seed = "";
public int roomSize = 12;
void Start () {
if(isServer){
GenSeedString();
CmdSyncSeed(seed);
}
}
public void GenSeedString(){
string temp = "";
for(int i=0; i < 800; i++){
int n = Random.Range(0,roomSize);
temp = temp +n+"%";
}
seed = temp;
}
[Command]
void CmdSyncSeed(string s){
seed = s;
}
When I load it up the seeds just aren’t the same between client and server?