Problem with using Unity Spawnsystem (Unet / Multiplayer)
I am trying to spawn objects over Unet but somehow it only works when the host spawns them.
Those are the functions i use to spawn my objects. They are both part of a script which is attached to my playerprefab. red_road, blue_road and so on have are object prefabs which have a networking component attached to them.
//Will spawn a road depending on the current selection.
public void SpawnRoad(Vector3 position, Quaternion rotation)
{
GameObject road;
switch (currentselection)
{
case 0:
road = road_red;
break;
case 1:
road = road_blue;
break;
case 2:
road = road_yellow;
break;
default:
road = road_green;
break;
}
CmdSpawnObject(road, position, rotation);
}
This is the command which gets called by the function above:
//Will spawn the passed object.
[Command]
void CmdSpawnObject(GameObject road, Vector3 position, Quaternion rotation)
{
GameObject spawnedroad = Instantiate(road, position, rotation);
NetworkServer.Spawn(spawnedroad);
}
SpawnRoad() itself gets called by a trigger. Whenever the player clicks on that trigger the trigger will pass its position and rotation to the function.
Any idea what is wrong here ?
Your answer
Follow this Question
Related Questions
Unet - spawning bullets, two issues 1 Answer
Synchronize child objects,multiplayer 0 Answers
Setting function to run on all clients but only work on the player that called it 0 Answers
[uNET] Instantiated gameobjects not syncing for new clients 1 Answer
[UNET] Syncing the position of a non-player object such as a trap (no player authority whatsoever) 3 Answers