mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
44 lines
No EOL
1 KiB
C#
44 lines
No EOL
1 KiB
C#
using Godot;
|
|
|
|
namespace Cirno.Scripts.Interactables;
|
|
|
|
public partial class AreaTrigger : Area2D
|
|
{
|
|
[Export] public Node2D Target { get; set; }
|
|
|
|
[Export] public ActivationType ActivationType { get; set; } = Scripts.ActivationType.Toggle;
|
|
|
|
[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;
|
|
|
|
if (Target is not IActivable target)
|
|
{
|
|
GD.PrintErr($"Target {Target.Name} is not activable");
|
|
return false;
|
|
}
|
|
target.Activate();
|
|
|
|
_activations++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
private void _on_area_entered(Area2D area)
|
|
{
|
|
if (area is not InteractionController player) return;
|
|
Activate(player);
|
|
}
|
|
} |