/// <summary> /// Called on the client when connected to a server. /// <para>The default implementation of this function sets the client as ready and adds a player. Override the function to dictate what happens when the client connects.</para> /// </summary> /// <param name="conn">Connection to the server.</param> public override void OnClientConnect(NetworkConnection conn) { base.OnClientConnect(conn); // you can send the message here, or wherever else you want CreateRPGCharacterMessage characterMessage = new CreateRPGCharacterMessage { race = Race.Dwarvish, name = "Bamarin", skinColor = Color.black, characterClass = RPGClass.Wizard }; conn.Send(characterMessage); }
void OnCreateCharacter(NetworkConnection conn, CreateRPGCharacterMessage 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(spawnPrefabs[(int)message.characterClass]);//spawnPrefabs[(int)message.characterClass] // Apply data from the message however appropriate for your game // Typically Player would be a component you write with syncvars or properties Character player = gameobject.GetComponent <Character>(); player.race = message.race; player.name = message.name; player.skinColor = message.skinColor; player.characterClass = message.characterClass; // call this to use this gameobject as the primary controller NetworkServer.AddPlayerForConnection(conn, gameobject); }