using Unity.Burst; using Unity.Entities; using Unity.Transforms; using Unity.Mathematics; namespace HappyForest.Prototypen { [BurstCompile] public partial struct PilleWanderSystem : ISystem { [BurstCompile] public void OnCreate(ref SystemState state) { state.RequireForUpdate(); } [BurstCompile] public void OnUpdate(ref SystemState state) { float deltaTime = SystemAPI.Time.DeltaTime; // Ein EntityCommandBuffer wird benötigt, um Entities sicher zu zerstören, // während wir gerade über sie iterieren. var ecb = SystemAPI.GetSingleton().CreateCommandBuffer(state.WorldUnmanaged); // Iteriere über alle Entities, die eine Position (LocalTransform) und unsere WanderData haben foreach (var (transform, wanderData, entity) in SystemAPI.Query, RefRO>().WithEntityAccess()) { // 1. Bewegen (Aktuelle Position + Richtung * Geschwindigkeit * Zeit) transform.ValueRW.Position += wanderData.ValueRO.Direction * wanderData.ValueRO.Speed * deltaTime; // 2. Abgrund-Check (Runtergefallen?) if (transform.ValueRO.Position.y < -10f) { ecb.DestroyEntity(entity); } } } } }