- Home /
Question by
carbonroast · Feb 06, 2018 at 12:33 AM ·
multiplayermultiplayer-networkingspawningclient-servercommand
Networking - Spawning non Player Object
I am attempting to learn network coding. I trying to create a grid for which players can build on. I can spawn the grid and it shows up on both the client and the server however some variables are not on the client specifically the layer mask. This code is attached to a game object that exist in the scene. It is not attached to any playerconnectionobjects. I have tried spawning it with authority, using a RPC call as well as a command. I am misunderstanding something but havent the slightest idea what.
My code is below.
void Start () {
if(!isServer){
return;
}
SpawnWorld();
}
void SpawnWorld(){
GameObject _tiles = new GameObject();
_tiles.transform.parent = this.transform;
_tiles.name = "Tiles";
for (int i = 0; i < xSize; i++) {
for (int j = 0; j < ySize; j++) {
GameObject childObject = (GameObject)Instantiate (tile);
childObject.transform.parent = _tiles.transform;
childObject.transform.position = new Vector3 (i+(float).5, (float)-.5,j+(float).5);
childObject.name = i + " " + j;
childObject.layer = LayerMask.NameToLayer ("Tile");
TilesManager.RegisterTiles (childObject.name, childObject);
NetworkServer.Spawn (childObject);
}
}
print ("CmdSpawnWorld : World Created");
}
Thanks!
Comment