forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrespawnMoverSystem.cs
More file actions
41 lines (35 loc) · 1.32 KB
/
Copy pathPrespawnMoverSystem.cs
File metadata and controls
41 lines (35 loc) · 1.32 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
36
37
38
39
40
41
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using Unity.NetCode;
namespace Samples.HelloNetcode
{
[UpdateInGroup(typeof(HelloNetcodeSystemGroup))]
[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)]
public partial class PrespawnMoverSystem : SystemBase
{
protected override void OnCreate()
{
RequireForUpdate<EnablePrespawn>();
}
protected override void OnUpdate()
{
var time = SystemAPI.Time.ElapsedTime;
var deltaTime = SystemAPI.Time.DeltaTime;
Entities.WithName("MovePrespawnBarrels").ForEach((Entity entity, ref GhostInstance ghost, ref LocalTransform transform,
ref PrespawnData data) =>
{
// After 2 seconds make the barrels slide between -2 and 2 on the x axis
if (time > 2)
{
data.Value++;
if (transform.Position.x > 2f)
data.Direction = -1f;
else if (transform.Position.x < -2f)
data.Direction = 1f;
transform.Position = new float3(transform.Position.x + deltaTime * data.Direction, transform.Position.y, transform.Position.z);
}
}).Schedule();
}
}
}