public void OnCollide(GameObject other) { // Cancel if the enemy is currently spawning if (!enemy.IsSpawned) { return; } FrameworkDebug.LogCollision(DateTime.Now + ":" + DateTime.Now.Millisecond + " " + enemy.GetType().Name + " collision with " + other.GetType().Name); switch (other) { case AbstractEnemy _: // Get if there is a no overlap component var hasNoOverlap = other.GetComponents <CollisionComponent>().Aggregate(false, (b, component) => b || component is EnemyNoOverlapCollisionController); // Enemies should not overlap if the component is present if (hasNoOverlap) { GetComponent <ColliderComponent>().UndoOverlap(other.GetComponent <ColliderComponent>()); } break; } }
public void OnCollide(GameObject other) { // OVERKILL avoidance: // Avoid duplicate shots hit the enemy and when the enemy is spawning it shell not get killed if (!enemy.IsAlive || !enemy.IsSpawned) { return; } FrameworkDebug.LogCollision(DateTime.Now + ":" + DateTime.Now.Millisecond + " " + enemy.GetType().Name + " collision with " + other.GetType().Name); switch (other) { case Shot.Shot shot: shot.OwningPlayer.Attributes.OnEnemyKill(enemy); // Destroy the shot and spawn the explosion Scene.Current.Spawn(new EnemyExplosionParticleEmitterObject(GameObject as AbstractEnemy)); Scene.Current.Destroy(GameObject); // For now, destroy also the shot (could also have an explosion like effect) Scene.Current.Destroy(shot); break; } }