Hello,
I’m having a problem with ECS systems.
I’m working on a PVP game between 2 teams, each team has a spawn zone.
Spawn zones are entities just like players.
In the following code, I tag players who have run out of lives with a WaitForRespawnTag.
In a second system, I want the tagged players to teleport to their respective spawn zones.
However, I can’t find a “clean” way to make the player and spawner entities communicate with each other…
I’ve found this solution, but I don’t quite understand it, and the sintax is obsolete today…
Otherwise, here is my code:
public partial struct SpawnerSystem : ISystem
{
public void OnUpdate(ref SystemState state)
{
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
foreach (var (health, entity) in SystemAPI.Query<RefRO<Health>>()
.WithAll<Simulate>()
.WithAll<PlayerTempsTag>()
.WithEntityAccess())
{
if (entityManager.HasComponent<WaitingForRespawnTag>(entity)) continue;
ref readonly Health hp = ref health.ValueRO;
if (hp.Value <= 0)
{
entityManager.AddComponent<WaitingForRespawnTag>(entity);
}
}
}
}
public partial struct RespawnSystem : ISystem
{
public void OnUpdate()
{
foreach (var waiterLocalTransform in SystemAPI.Query<RefRW<LocalTransform>>()
.WithAll<WaitingForRespawnTag>()
.WithAll<NatifTeamTag>())
{
ref LocalTransform waiterTransform = ref waiterLocalTransform.ValueRW;
foreach (var (physicsCollider, spawnerComponent, spawnerLocalTransform) in SystemAPI.Query<RefRO<PhysicsCollider>, RefRO<SpawnerComponent>, RefRO<LocalTransform>>()
.WithAll<NatifTeamTag>())
{
ref readonly PhysicsCollider collider = ref physicsCollider.ValueRO;
ref readonly SpawnerComponent spawnerData = ref spawnerComponent.ValueRO;
ref readonly LocalTransform spawnerTransform = ref spawnerLocalTransform.ValueRO;
//???
}
}
}
}