mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-10 16:45:53 +00:00
New player add method
This commit is contained in:
parent
83e8b9081c
commit
a235183c61
8 changed files with 116 additions and 58 deletions
54
Scripts/GameManager.cs
Normal file
54
Scripts/GameManager.cs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
using Godot;
|
||||
using System;
|
||||
using Cirno.Scripts;
|
||||
|
||||
public partial class GameManager : Node2D
|
||||
{
|
||||
private Hud _hud;
|
||||
|
||||
private PlayerMovement _player;
|
||||
|
||||
private Node2D _cameraTarget;
|
||||
|
||||
[Export]
|
||||
public PackedScene PlayerTemplate { get; set; }
|
||||
|
||||
[Export]
|
||||
public Marker2D PlayerSpawnMarker { get; set; }
|
||||
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
_hud = GetNode<Hud>("HUD");
|
||||
_cameraTarget = GetNode<Node2D>("CameraTarget");
|
||||
|
||||
if (PlayerSpawnMarker != null)
|
||||
{
|
||||
SpawnPlayer();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
}
|
||||
|
||||
public void SpawnPlayer()
|
||||
{
|
||||
if (_player == null)
|
||||
{
|
||||
//_player = this.CreateChild<PlayerMovement>(PlayerTemplate, PlayerSpawnMarker.Position );
|
||||
_player = PlayerTemplate.Instantiate<PlayerMovement>();
|
||||
|
||||
this.CallDeferred("add_child", _player);
|
||||
_player.Transform = this.GlobalTransform;
|
||||
|
||||
_player.GlobalPosition = PlayerSpawnMarker.Position;
|
||||
|
||||
_cameraTarget.Reparent(_player, true);
|
||||
_cameraTarget.GlobalPosition = _player.Position;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue