forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDespawnHealthBarSystem.cs
More file actions
31 lines (29 loc) · 882 Bytes
/
Copy pathDespawnHealthBarSystem.cs
File metadata and controls
31 lines (29 loc) · 882 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
using Unity.Entities;
using UnityEngine;
namespace Samples.HelloNetcode
{
#if !UNITY_DISABLE_MANAGED_COMPONENTS
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation)]
[UpdateInGroup(typeof(PresentationSystemGroup))]
[RequireMatchingQueriesForUpdate]
public partial struct DespawnHealthBarSystem : ISystem
{
public void OnUpdate(ref SystemState state)
{
foreach (var (health, ui) in SystemAPI.Query<RefRO<Health>, HealthUI>())
{
if (health.ValueRO.CurrentHitPoints > 0)
{
continue;
}
if (ui.HealthBar != null)
{
Object.Destroy(ui.HealthBar.gameObject);
ui.HealthBar = null;
ui.HealthSlider = null;
}
}
}
}
#endif
}