You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.1 KiB
48 lines
1.1 KiB
using Godot;
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
} |