example-grass/Eat Da Rich/Eat/Eat.cs

54 lines
940 B
C#

using Godot;
using System.Collections;
using System.Collections.Generic;
using Godot.Collections;
namespace Rokojori
{
[GlobalClass,Tool]
public partial class Eat:Action
{
[Export]
public OnCollision onCollision;
[Export]
public Action onAteSomething;
[Export]
public Pointer pointer;
protected override void _OnTrigger()
{
var pigs = onCollision.GetNodesInside();
var hasEaten = false;
pigs.ForEach(
( p )=>
{
var eatable = p.Get<Eatable>();
this.LogInfo( eatable );
if ( eatable == null || ! eatable.isEatable )
{
return;
}
eatable.GetEaten();
hasEaten = true;
}
);
if ( hasEaten )
{
Trigger( onAteSomething );
}
this.LogInfo( pigs );
}
}
}