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
24 lines (22 loc) · 769 Bytes
/
Copy pathHitTargetMoveSystem.cs
File metadata and controls
24 lines (22 loc) · 769 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
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)
{
foreach (var (trans, hitTarget) in SystemAPI.Query<RefRW<LocalTransform>, RefRO<HitTarget>>())
{
trans.ValueRW.Position.x = (float) math.sin(SystemAPI.Time.ElapsedTime * hitTarget.ValueRO.Speed) * hitTarget.ValueRO.MovingRange;
}
}
}
}