forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntityKillerBehaviour.cs
More file actions
37 lines (33 loc) · 920 Bytes
/
Copy pathEntityKillerBehaviour.cs
File metadata and controls
37 lines (33 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using Unity.Physics;
using Unity.Collections;
using Unity.Entities;
using System;
using UnityEngine;
public struct EntityKiller : IComponentData
{
public int TimeToDie;
}
public class EntityKillerBehaviour : MonoBehaviour, IConvertGameObjectToEntity
{
public int TimeToDie;
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
dstManager.AddComponentData<EntityKiller>(entity, new EntityKiller() { TimeToDie = TimeToDie });
}
}
public class EntityKillerSystem : ComponentSystem
{
protected override void OnUpdate()
{
Entities.ForEach(
(Entity entity, ref EntityKiller killer) =>
{
killer.TimeToDie--;
if(killer.TimeToDie <= 0)
{
PostUpdateCommands.DestroyEntity(entity);
}
}
);
}
}