Files
przygody-pana-cegly/scripts/components/LifetimeComponent.cs

27 lines
627 B
C#

using Godot;
namespace Mr.BrickAdventures.scripts.components;
public partial class LifetimeComponent : Node
{
[Export] public float LifeTime { get; set; } = 5.0f;
private Timer _lifetimeTimer;
public override void _Ready()
{
_lifetimeTimer = new Timer();
_lifetimeTimer.WaitTime = LifeTime;
_lifetimeTimer.OneShot = true;
_lifetimeTimer.Autostart = true;
_lifetimeTimer.Timeout += OnLifetimeTimeout;
AddChild(_lifetimeTimer);
_lifetimeTimer.Start();
}
private void OnLifetimeTimeout()
{
Owner.QueueFree();
}
}