forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDamageSystem.cs
More file actions
28 lines (26 loc) · 886 Bytes
/
Copy pathDamageSystem.cs
File metadata and controls
28 lines (26 loc) · 886 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
using Unity.Entities;
using Unity.NetCode;
namespace Samples.HelloNetcode
{
[RequireMatchingQueriesForUpdate]
[UpdateInGroup(typeof(HelloNetcodePredictedSystemGroup))]
[UpdateAfter(typeof(ShootingSystem))]
public partial struct DamageSystem : ISystem
{
public void OnUpdate(ref SystemState state)
{
var healthFromEntity = SystemAPI.GetComponentLookup<Health>();
foreach (var hit in SystemAPI.Query<RefRW<Hit>>())
{
if (!healthFromEntity.HasComponent(hit.ValueRO.Entity))
{
continue;
}
var health = healthFromEntity[hit.ValueRO.Entity];
health.CurrentHitPoints -= 20;
healthFromEntity[hit.ValueRO.Entity] = health;
hit.ValueRW.Entity = Entity.Null;
}
}
}
}