2D-Platformer/Assets/Scripts/Systems/EntityDeathSystem.cs
2022-02-12 12:53:50 +02:00

34 lines
No EOL
742 B
C#

using Events;
using Unity.Entities;
using UnityEngine;
namespace DefaultNamespace
{
[UpdateInGroup(typeof(LateSimulationSystemGroup))]
public class EntityDeathSystem : AdvancedComponentSystem
{
protected override void OnSystemUpdate()
{
Entities.ForEach(
(Entity entity, ref EntityDeathEvent e) =>
{
if (EntityManager.HasComponent<Transform>(entity))
{
PostUpdateActions.Enqueue(
() =>
{
Object.Destroy(EntityManager.GetComponentObject<Transform>(entity).gameObject);
if (EntityManager.Exists(entity))
{
EntityManager.DestroyEntity(entity);
}
});
}
else
{
PostUpdateCommands.DestroyEntity(entity);
}
});
}
}
}