cirnogodot/Scripts/Interactables/AreaTrigger.cs

37 lines
810 B
C#
Raw Normal View History

2025-02-06 09:44:21 +01:00
using Godot;
namespace Cirno.Scripts.Interactables;
public partial class AreaTrigger : Area2D
{
[Export] public Activable Target { get; set; }
[Export] public bool OneTime { get; set; }
[Export] public bool DoNotActivateOnFirst { get; set; }
private int _activations = 0;
public bool Activate(InteractionController player)
{
if (_activations == 0 && DoNotActivateOnFirst)
{
_activations++;
return false;
}
if (OneTime && _activations > 0) return false;
Target?.Activate();
_activations++;
return true;
}
private void _on_area_entered(Area2D area)
{
if (area is not InteractionController player) return;
Activate(player);
}
}