how to instantiate something across the network in mirror unity code example
Example: custom player spawner mirror
public class MMONetworkManager : NetworkManager
{
public override void OnStartServer()
{
base.OnStartServer();
NetworkServer.RegisterHandler<CreateMMOCharacterMessage>(OnCreateCharacter);
}
public override void OnClientConnect(NetworkConnection conn)
{
base.OnClientConnect(conn);
CreateMMOCharacterMessage characterMessage = new CreateMMOCharacterMessage
{
race = Race.Elvish,
name = "Joe Gaba Gaba",
hairColor = Color.red,
eyeColor = Color.green
};
conn.Send(characterMessage);
}
void OnCreateCharacter(NetworkConnection conn, CreateMMOCharacterMessage message)
{
GameObject gameobject = Instantiate(playerPrefab);
Player player = gameobject.GetComponent<Player>();
player.hairColor = message.hairColor;
player.eyeColor = message.eyeColor;
player.name = message.name;
player.race = message.race;
NetworkServer.AddPlayerForConnection(conn, gameobject);
}
}