mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-10 19:35:54 +00:00
Area trigger
This commit is contained in:
parent
10ab6fce1a
commit
77765a581e
3 changed files with 58 additions and 1 deletions
37
Scripts/Interactables/AreaTrigger.cs
Normal file
37
Scripts/Interactables/AreaTrigger.cs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue