private void OnTriggerEnter2D(Collider2D other) { Health health = other.GetComponent <Health>(); if (health != null) { ICharacter hitCharacter = other.GetComponent <ICharacter>(); if (hitCharacter.CharacterType != CharacterType) { health.TakeDamage(Damage); } return; } DestructibleTilemap destructibleTilemap = other.GetComponent <DestructibleTilemap>(); if (destructibleTilemap != null) { destructibleTilemap.DestroyTile(transform.position); return; } Bomb bomb = other.GetComponent <Bomb>(); if (bomb != null && bomb.CharacterType == CharacterType && bomb.Destination == null) { bomb.Explode(); } }
private void OnTriggerEnter2D(Collider2D other) { bool hasCollided = false; Health health = other.GetComponent <Health>(); if (health != null) { ICharacter hitCharacter = other.GetComponent <ICharacter>(); if (hitCharacter.CharacterType != CharacterType) { health.TakeDamage(Damage); hasCollided = true; onTargetHit?.Invoke(other); DestroyProjectile(); } } DestructibleTilemap destructibleTilemap = other.GetComponent <DestructibleTilemap>(); if (destructibleTilemap != null) { hasCollided = true; destructibleTilemap.DestroyTile(transform.position); } if (other.GetComponent <IDestroyProjectile>() != null) { hasCollided = true; DestroyProjectile(); } if (hasCollided) { onCollision?.Invoke(transform.position); } }
void checkTilemapCollision(Collider2D collider) { DestructibleTilemap dtm = collider.gameObject.GetComponent <DestructibleTilemap>(); if (dtm == null) { return; } Vector3 origin = _boxCollider2D.transform.position; RaycastHit2D hit = Physics2D.BoxCast(_boxCollider2D.transform.position, _boxCollider2D.size, transform.rotation.eulerAngles.z, transform.right, 0.01f, PlatformMask); dtm.DamageTiles(hit.point, DamageCaused, radius); }