rj-action-library-godot-dev.../Scripts/GameJam/Physics/OnCollision.cs

43 lines
725 B
C#

using Godot;
using Rokojori;
namespace GameJam
{
[GlobalClass]
public partial class OnCollision:Node
{
[Export]
public Area3D area;
[Export]
public RJAction onEntered;
[Export]
public RJAction onExit;
public override void _Ready()
{
if ( area == null )
{
return;
}
area.AreaEntered += ev => { TriggerOnEnter(); };
area.BodyEntered += ev => { TriggerOnEnter(); };
area.AreaExited += ev => { TriggerOnExited(); };
area.BodyExited += ev => { TriggerOnExited(); };
}
void TriggerOnEnter()
{
Actions.Trigger( onEntered );
}
void TriggerOnExited()
{
Actions.Trigger( onExit );
}
}
}