Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

custom player spawner mirror

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

        NetworkServer.RegisterHandler<CreateMMOCharacterMessage>(OnCreateCharacter);
    }

    public override void OnClientConnect(NetworkConnection conn)
    {
        base.OnClientConnect(conn);

        // you can send the message here, or wherever else you want
        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)
    {
        // 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.name = message.name;
        player.race = message.race;

        // call this to use this gameobject as the primary controller
        NetworkServer.AddPlayerForConnection(conn, gameobject);
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# order by descending on 2 values 
Csharp :: c# system.io check if file exists 
Csharp :: how to disable scale anti-aliasing in monogame 
Csharp :: c sharp tenery operator on an action 
Csharp :: f# list map function 
Csharp :: c# dictionary key set 
Csharp :: create new directory netrw 
Csharp :: c sharp switch forms 
Csharp :: unity download image from online 
Csharp :: erlang start net kernel 
Csharp :: AutoMapper Add Assemblies 
Csharp :: c# linq unique by property 
Csharp :: C# read GroupComponent using regex 
Csharp :: telerik mvc grid unbound column 
Csharp :: credit card validation in c# 
Csharp :: c# stringwriter encoding iso-8859-1 example 
Csharp :: trimend c# 
Csharp :: c# ipaddress to integer 
Csharp :: lsbCat.Items.Clear();lsbCat.Items.AddRange(Cats.ToArray());txtCat.Clear(); 
Csharp :: c# servercertificatevalidationcallback 
Csharp :: umbraco cannot start. a connection string is configured but umbraco cannot connect to the database. 
Csharp :: asp.net Read raw Body 
Csharp :: unity next level trigger 
Csharp :: c# ulong 
Csharp :: esaddex34 
Csharp :: c# show hidden window wpf 
Csharp :: dotnet target specific framework 
Csharp :: stateteach.net 
Csharp :: xamarin xaml viewmodel 
Csharp :: ip validation .net core 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =