Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Physics;
using Unity.Mathematics;
using Unity.Transforms;
using Unity.Entities;
using Unity.Physics.Systems;
[AlwaysUpdateSystem]
public class HitTestSystem : ComponentSystem
{
BuildPhysicsWorld m_BuildPhysicsWorldSystem;
StepPhysicsWorld m_StepPhysicsWorldSystem;
protected override void OnCreateManager()
{
m_BuildPhysicsWorldSystem = World.GetOrCreateManager<BuildPhysicsWorld>();
m_StepPhysicsWorldSystem = World.GetOrCreateManager<StepPhysicsWorld>();
}
protected override void OnUpdate()
{
foreach(var contactEvent in m_StepPhysicsWorldSystem.Simulation.CollisionEvents)
{
var physicsWorld = m_BuildPhysicsWorldSystem.PhysicsWorld;
var bodyA = physicsWorld.Bodies[contactEvent.BodyIndices.BodyAIndex];
var bodyB = physicsWorld.Bodies[contactEvent.BodyIndices.BodyBIndex];
PostUpdateCommands.DestroyEntity(bodyA.Entity);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.