How to make multiplayer in c#

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By daniel500013

HI i have a question because nearly i start make a multiplayer game and project gone fine but tutorial aobut multiplayer in godot are written mostly in gdscript. I tried translate gdscript to c# but i dont understand some functions in gdscripts. So i asking you what is bad in under code or somebody know good tutorial how to make multiplayer game in c#? in general sorry for my bad Englidh

	TextEdit textEdit;

string ip = "192.168.0.100";
int port = 31400;
int max_client = 2;

public override void _Ready()
{
	textEdit = GetNode<TextEdit>("TextEdit");
}

public void enter_room()
{
	textEdit.Text = "Successfully joined room\n";
}


public void create_server()
{
	var peer = new NetworkedMultiplayerENet();
	peer.CreateServer(port, max_client);
	GetTree().SetNetworkPeer(peer);
	enter_room();

}

public void join_server()
{
	var peer = new NetworkedMultiplayerENet();
	peer.CreateClient(ip, port);
	GetTree().SetNetworkPeer(peer);
}

private void _on_Create_pressed()
{
	create_server();
}

private void _on_Join_pressed()
{
	join_server();
}

private void _on_Send_pressed()
{
	var id = GetTree().GetNetworkUniqueId();

	Rpc("recieve_call", textEdit.Text);
	GD.Print(id);
}

public async void recieve_call(string msg)
{
	textEdit.Text += msg + "\r\n";
	GD.Print(msg + " p");
}

Do you have a link to the Tutorial you tried to use? Maybe I can help you to translate that into C#.

juppi | 2020-05-25 20:12