Hello, I destroy target entity in this system (bullet hit bot and both should be destroyed)
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
public class DestructionSystem : ComponentSystem
{
private EntityManager entityManager;
protected override void OnStartRunning()
{
entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
}
protected override void OnUpdate()
{
Entities.WithAll<Destructor>().ForEach((Entity vilian, ref Translation vilianTrans, ref Destructor destructor) =>
{
float3 vilianPos = vilianTrans.Value;
Entities.WithAll<Destructable>().ForEach((Entity victim, ref Translation victimTrans, ref Destructable destructable) =>
{
if (math.distance(vilianPos, victimTrans.Value) < 1)
{
entityManager.DestroyEntity(vilian);
entityManager.DestroyEntity(victim);
}
});
});
}
}
But in the other system I have code like this
public class AttackSystem : ComponentSystem
{
protected override void OnUpdate()
{
Entities.WithAll<BehaviourStateAttacking>().ForEach((
Entity entity,
ref Translation translation,
ref Rotation rotation,
ref BehaviourStateAttacking behaviourStateAttacking,
ref Turning turning,
ref ShootTimer shootTimer
) =>
{
float3 myPos = translation.Value;
quaternion myRot = rotation.Value;
float turningSpeed = turning.TurningSpeed;
float3 turgetPoint = World.DefaultGameObjectInjectionWorld.EntityManager.GetComponentData<Translation>(behaviourStateAttacking.AttackTarget).Value;
In the last published line I have an error that sais “ArgumentException: A component with type:Translation has not been added to the entity.”
how to fix the issue?