forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHitTargetMoveSystem.cs
More file actions
35 lines (29 loc) · 1.04 KB
/
Copy pathHitTargetMoveSystem.cs
File metadata and controls
35 lines (29 loc) · 1.04 KB
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
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
namespace Samples.HelloNetcode
{
[UpdateInGroup(typeof(HelloNetcodeSystemGroup))]
[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)]
public partial struct HitTargetMoveSystem : ISystem
{
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<HitTarget>();
}
public void OnUpdate(ref SystemState state)
{
var timeDeltaTime = SystemAPI.Time.DeltaTime;
foreach (var (trans, hitTarget) in SystemAPI.Query<RefRW<LocalTransform>, RefRW<HitTarget>>())
{
var deltaMove = timeDeltaTime * hitTarget.ValueRW.Speed;
hitTarget.ValueRW.Moved += deltaMove;
trans.ValueRW.Position.x += deltaMove;
if (math.abs(hitTarget.ValueRW.Moved) > hitTarget.ValueRW.MovingRange)
{
hitTarget.ValueRW.Speed = -hitTarget.ValueRW.Speed;
}
}
}
}
}