-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cs
More file actions
53 lines (42 loc) · 1.2 KB
/
Copy pathMain.cs
File metadata and controls
53 lines (42 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using Godot;
public partial class Main : Node3D
{
[Export]
public PackedScene PlayerScene;
[Export]
public PackedScene RemotePlayerScene;
MultiplayerSpawner _spawner;
Node3D _spawn;
public override void _Ready()
{
_spawner = GetTree().CurrentScene.GetNode<MultiplayerSpawner>("MultiplayerSpawner");
_spawner.SpawnFunction = Callable.From<int, GodotObject>(CustomSpawn);
_spawn = GetTree().CurrentScene.GetNode<Node3D>("spawn");
if (!Multiplayer.IsServer())
return;
Multiplayer.PeerConnected += SpawnPlayer;
SpawnPlayer(1);
}
void SpawnPlayer(long id)
{
_spawner.Spawn((Variant)id);
}
Node CustomSpawn(int id)
{
Node3D player;
if (id == Multiplayer.GetUniqueId())
{
player = PlayerScene.Instantiate<Node3D>();
GD.Print("My id: ", id);
}
else
{
player = RemotePlayerScene.Instantiate<Node3D>();
GD.Print("Remote id: ", id, " My id: ", Multiplayer.GetUniqueId());
}
player.SetMultiplayerAuthority(id);
player.Name = id.ToString();
return player;
}
}