protected virtual void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Bullet") { var bullet = other.GetComponent <BulletController>(); if (bullet == null) { return; } var audioClip = AudioBullet; if (bullet.ArmorPiercing && !NotDestruction) { audioClip = AudioArmorPiercingBullet; Destroy(gameObject); } var layer = LayerMask.LayerToName(other.gameObject.layer); if (layer == "BulletPlayer1" || layer == "BulletPlayer2") { AudioManager.PlaySecondarySound(audioClip); } } }
private void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Bullet") { var bullet = other.GetComponent <BulletController>(); if (bullet != null) { if (bullet.FirstCollision) { return; } bullet.FirstCollision = true; } AudioManager.PlaySecondarySound(AudioDestroy1); AudioManager.PlaySecondarySound(AudioDestroy2); _spriteRenderer.sprite = Destroyed; _boxCollider.enabled = false; var obj = Instantiate(PrefabExplosion); var pos = transform.position; pos.z = PrefabExplosion.transform.position.z; obj.transform.position = transform.position; obj.Show(ExplosionController.ExplosionType.Object); GameManager.GameOver(); } }
protected override void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Bullet") { var bullet = other.GetComponent <BulletController>(); if (bullet == null) { return; } var layer = LayerMask.LayerToName(other.gameObject.layer); if (layer == "BulletPlayer1" || layer == "BulletPlayer2") { AudioManager.PlaySecondarySound(AudioBullet); } if (bullet.ArmorPiercing) { Destroy(gameObject); return; } var direction = bullet.DirectionFlight; if (direction == Direction.Bottom) { switch (_typeDestruction) { case TypeDestruction.None: DestructionTop(); break; case TypeDestruction.Right: SetBrickOneBottomLeft(); break; case TypeDestruction.Left: SetBrickOneBottomRight(); break; case TypeDestruction.Full: default: DestructionFull(); break; } } else if (direction == Direction.Left) { switch (_typeDestruction) { case TypeDestruction.None: DestructionRight(); break; case TypeDestruction.Top: SetBrickOneBottomLeft(); break; case TypeDestruction.Bottom: SetBrickOneTopLeft(); break; case TypeDestruction.Full: default: DestructionFull(); break; } } else if (direction == Direction.Top) { switch (_typeDestruction) { case TypeDestruction.None: DestructionBottom(); break; case TypeDestruction.Right: SetBrickOneTopLeft(); break; case TypeDestruction.Left: SetBrickOneTopRight(); break; case TypeDestruction.Full: default: DestructionFull(); break; } } else if (direction == Direction.Right) { switch (_typeDestruction) { case TypeDestruction.None: DestructionLeft(); break; case TypeDestruction.Top: SetBrickOneBottomRight(); break; case TypeDestruction.Bottom: SetBrickOneTopRight(); break; case TypeDestruction.Full: default: DestructionFull(); break; } } } }