Spawning fields works
This commit is contained in:
@@ -5,13 +5,44 @@ namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
public partial class FarmingControls : Node3D
|
||||
{
|
||||
[Export] private Sprite3D _hoeSprite;
|
||||
[Export] private PackedScene _fieldPrefab;
|
||||
[Export] private Node _fieldParent;
|
||||
[Export] private Node3D _movingPlayer;
|
||||
|
||||
private bool _hoeInHand = false;
|
||||
|
||||
public void ActivateHoe(bool activate)
|
||||
{
|
||||
_hoeSprite.Visible = !activate;
|
||||
_hoeInHand = !activate;
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if (@event.IsActionPressed("click") && _hoeInHand)
|
||||
{
|
||||
MakeField();
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Notification(int notification)
|
||||
{
|
||||
GD.Print("Player global position: " + _movingPlayer.GlobalPosition);
|
||||
}
|
||||
|
||||
private void MakeField()
|
||||
{
|
||||
if(_fieldParent == null || _fieldPrefab == null)
|
||||
return;
|
||||
|
||||
Node fieldInstance = _fieldPrefab.Instantiate();
|
||||
|
||||
if (fieldInstance is Node3D field3d)
|
||||
{
|
||||
field3d.Position = _movingPlayer.GlobalPosition;
|
||||
}
|
||||
|
||||
_fieldParent.AddChild(fieldInstance);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user