53 lines
891 B
C#
53 lines
891 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BITKit.Entities;
|
|
using UnityEngine;
|
|
|
|
namespace BITKit
|
|
{
|
|
public class AutoRespawnComponent : EntityComponent,IHealthCallback,IAction
|
|
{
|
|
[SerializeField] private IntervalUpdate respawnInterval;
|
|
private bool requestRespawn;
|
|
public override void OnAwake()
|
|
{
|
|
entity.RegisterCallback<IHealthCallback>(this);
|
|
}
|
|
|
|
public override void OnUpdate(float deltaTime)
|
|
{
|
|
if (requestRespawn && respawnInterval.AllowUpdate)
|
|
{
|
|
requestRespawn = false;
|
|
Execute();
|
|
}
|
|
}
|
|
|
|
public void OnSetAlive(bool alive)
|
|
{
|
|
if (alive)
|
|
{
|
|
requestRespawn = false;
|
|
}
|
|
else
|
|
{
|
|
respawnInterval.Reset();
|
|
requestRespawn = true;
|
|
}
|
|
}
|
|
public void OnSetHP(int hp)
|
|
{
|
|
|
|
}
|
|
|
|
public void Execute()
|
|
{
|
|
if (TryGetComponent<IHealth>(out var health))
|
|
{
|
|
health.HealthPoint = 100;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|