21 lines
755 B
GDScript
21 lines
755 B
GDScript
class_name PlayerSpawner
|
|
extends Node3D
|
|
|
|
const PLAYER_SCENE: PackedScene = preload("res://entities/player.tscn")
|
|
|
|
func _spawn_player(player: Dictionary) -> CharacterBody3D:
|
|
var player_instance: Player = PLAYER_SCENE.instantiate()
|
|
var id: int = player.id
|
|
player_instance.position = position
|
|
player_instance.hunter = player.hunter
|
|
player_instance.set_multiplayer_authority(id)
|
|
return player_instance
|
|
|
|
func _ready() -> void:
|
|
if $MultiplayerSpawner is MultiplayerSpawner:
|
|
($MultiplayerSpawner as MultiplayerSpawner).spawn_function = _spawn_player
|
|
|
|
func spawn_player(player: Dictionary) -> void:
|
|
if $MultiplayerSpawner is MultiplayerSpawner:
|
|
if ($MultiplayerSpawner as MultiplayerSpawner).spawn(player) == null:
|
|
print("Failed to spawn player.")
|