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
26 lines (25 loc) · 837 Bytes
/
Copy pathDamageSystem.cs
File metadata and controls
26 lines (25 loc) · 837 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
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.TryGetComponent(hit.ValueRO.Victim, out var health))
{
continue;
}
health.CurrentHitPoints -= 20;
healthFromEntity[hit.ValueRO.Victim] = health;
hit.ValueRW.Victim = Entity.Null;
}
}
}
}