private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Destructable" && isReleased) { StartCoroutine(spriteChange()); Object.Instantiate(particleSystem, base.gameObject.transform.position, base.gameObject.transform.rotation); BlockDamage component = collision.gameObject.GetComponent <BlockDamage>(); component.minusHealth(damage); component.minusHealth(1); } }
private void AddExplosionForce(Rigidbody2D rb, float explosionForce, Vector2 explodingPosition, float radius, float upwardsModifier = 0f, ForceMode2D mode = ForceMode2D.Impulse) { BlockDamage component = rb.GetComponent <BlockDamage>(); if (canExplode) { explosieAudio.clip = explosie; Vector2 a = rb.position - explodingPosition; float magnitude = a.magnitude; explosieAudio.Play(); if (magnitude < radius / 2f) { component.minusHealth(3); } else { if (magnitude > radius / 3f && magnitude < radius / 2f) { component.minusHealth(2); } if (magnitude > radius && magnitude < radius / 3f) { component.minusHealth(1); } } if (upwardsModifier == 0f) { a /= magnitude; } else { a.Normalize(); } rb.AddForce(Mathf.Lerp(0f, explosionForce, radius / magnitude) * a, mode); } Object.Destroy(base.gameObject); }