forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoveSystem.cs
More file actions
44 lines (39 loc) · 1.38 KB
/
Copy pathMoveSystem.cs
File metadata and controls
44 lines (39 loc) · 1.38 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
42
43
44
using Streaming.SceneManagement.Common;
using Unity.Burst;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
namespace Streaming.SceneManagement.StreamingVolume
{
public partial struct MoveSystem : ISystem
{
[BurstCompile]
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<Player>();
}
public void OnUpdate(ref SystemState state)
{
var camera = Camera.main;
if (camera == null)
{
return;
}
var cameraTransform = camera.transform;
var deltaTime = SystemAPI.Time.DeltaTime;
var horizontal = Input.GetAxis("Horizontal");
var vertical = Input.GetAxis("Vertical");
var input = new float2(horizontal, vertical);
foreach (var (transform, player) in
SystemAPI.Query<RefRW<LocalTransform>, RefRO<Player>>()
.WithAll<Relevant>())
{
transform.ValueRW.Position += new float3(input.x, 0.0f, input.y) * player.ValueRO.Speed * deltaTime;
transform.ValueRW.Position.y = 1f;
cameraTransform.position = transform.ValueRW.Position + player.ValueRO.CameraOffset;
cameraTransform.LookAt(transform.ValueRW.Position);
}
}
}
}