Answers for "custom player spawner mirror"


custom player spawner mirror

//You need to create a message handler
public class MMONetworkManager : NetworkManager
    public override void OnStartServer()


    public override void OnClientConnect(NetworkConnection conn)

        // you can send the message here, or wherever else you want
        CreateMMOCharacterMessage characterMessage = new CreateMMOCharacterMessage
            race = Race.Elvish,
            name = "Joe Gaba Gaba",
            hairColor =,
            eyeColor =


    void OnCreateCharacter(NetworkConnection conn, CreateMMOCharacterMessage message)
        // playerPrefab is the one assigned in the inspector in Network
        // Manager but you can use different prefabs per race for example
        GameObject gameobject = Instantiate(playerPrefab);

        // Apply data from the message however appropriate for your game
        // Typically Player would be a component you write with syncvars or properties
        Player player = gameobject.GetComponent<Player>();
        player.hairColor = message.hairColor;
        player.eyeColor = message.eyeColor; =;
        player.race = message.race;

        // call this to use this gameobject as the primary controller
        NetworkServer.AddPlayerForConnection(conn, gameobject);
Posted by: Guest on June-02-2020

C# Answers by Framework

Browse Popular Code Answers by Language