- Home /
Question about Unet and spawning
I've set up a multiplayer game with simple network spawner using multiplayer lobby example. So far I have 2 different enemy types. One enemy type is primitive spawn and move forward and another is more complex - after it spawns after 3 seconds it shoots out another prefab (bullet) in 4 directions. From my understanding to spawn a networked object you need to Instantiate it and then use NetworkServer.Spawn(prefabName); yet if I do this it Spawns the prefab 2 times (same bullet in same position) I found this out by pausing client game and then moving one of the bullets to uncover the other in the inspector. Also my first enemy unit is fully synced even after pause it teleports the unit to position at host , but the spawned bullet just keeps on moving from same position as before pausing as if it was single player (the Instantiated one). My question is how to have only one bullet object spawned and not 2 and have them synced with host. This is the code of my class:
public void FireBullets(){
red = false;
var bulletTop = (GameObject)Instantiate (
bulletPrefab,
bulletSpawnTop.position,
bulletSpawnTop.rotation);
NetworkServer.Spawn (bulletTop);
var bulletBottom = (GameObject)Instantiate (
bulletPrefab,
bulletSpawnBottom.position,
bulletSpawnBottom.rotation);
NetworkServer.Spawn (bulletBottom);
var bulletLeft = (GameObject)Instantiate (
bulletPrefab,
bulletSpawnLeft.position,
bulletSpawnLeft.rotation);
NetworkServer.Spawn (bulletLeft);
NetworkServer.Spawn (bulletLeft);
var bulletRight = (GameObject)Instantiate (
bulletPrefab,
bulletSpawnRight.position,
bulletSpawnRight.rotation);
NetworkServer.Spawn (bulletRight);
}