/// <summary> /// /// </summary> /// <param name="collision"></param> private void OnCollisionEnter2D(Collision2D collision) { // Check if hit any game element GameElement element = collision.collider.GetComponent <GameElement>(); if (element != null) { element.HitByPlayerShot(); } else { // Check if hit a grave Grave grv = collision.collider.GetComponent <Grave>(); if (grv != null) { grv.HitByPlayerShot(); } } // Check if hit a treasure box TreasureBox treasure = collision.collider.GetComponent <TreasureBox>(); if (treasure != null) { treasure.Destroy(); } // Always destroy the shot when hits something this.Destroy(); }