mirror of
https://github.com/hanzoai/ProjectTinySamples.git
synced 2026-09-24 00:01:34 +00:00
25 lines
918 B
C#
25 lines
918 B
C#
using Unity.Entities;
|
|
using Unity.Mathematics;
|
|
using Unity.Transforms;
|
|
|
|
namespace TinyAquarium
|
|
{
|
|
public class PlayerSystem : SystemBase
|
|
{
|
|
protected override void OnUpdate()
|
|
{
|
|
Entities.ForEach((ref Player player, ref PlayerInput playerInput, ref Translation translation) =>
|
|
{
|
|
var newPosition = translation.Value +
|
|
new float3(0,
|
|
playerInput.InputAxis.y * player.Speed,
|
|
-playerInput.InputAxis.x * player.Speed);
|
|
translation.Value = new float3(newPosition.x,
|
|
// Clamp the player position to avoid going off screen
|
|
math.clamp(newPosition.y, player.VerticalLimit.y, player.VerticalLimit.x),
|
|
math.clamp(newPosition.z, player.HorizontalLimit.y, player.HorizontalLimit.x));
|
|
}).ScheduleParallel();
|
|
}
|
|
}
|
|
}
|