void OnCollisionEnter2D(Collision2D col) { if (col.gameObject.tag == "bullets") { sfxManager.PlaySFX(); hp -= 1; if (hp == 0) { isAlive = false; rb.AddForce((transform.position - col.transform.position).normalized * 5000 * Time.deltaTime, ForceMode2D.Impulse); levelDesign.AddScore(1); } else { rb.AddForce((transform.position - target.transform.position).normalized * knockback * Time.deltaTime, ForceMode2D.Impulse); } Destroy(col.gameObject); } else if (col.gameObject.tag == "Player") { Destroy(col.gameObject); levelDesign.GameOver(); } else if (col.gameObject.tag == "ground") { isGrounded = true; } }
void OnCollisionEnter2D(Collision2D col) { if (col.gameObject.tag == "bullets") { sfxManager.PlaySFX(); hp -= 1; if (hp == 0) { Destroy(col.gameObject); //Destroy(gameObject); GetComponent <SpriteRenderer>().sprite = burgerHit; BurgerDie(); levelDesign.AddScore(1); } } else if (col.gameObject.tag == "Player") { if (isAlive) { Destroy(col.gameObject); levelDesign.GameOver(); } } }