private void OnTriggerEnter2D(Collider2D collision) { // if player is within the trigger volume, apply force and damage if (collision.GetComponent <CustomPlayerController>() != null) { CustomPlayerController player = collision.GetComponent <CustomPlayerController>(); if (player.RB != null) { Vector2 dir = new Vector2(player.transform.position.x - transform.position.x, player.transform.position.y - transform.position.y).normalized; player.RB.AddForce(dir * explosionForce, ForceMode2D.Impulse); player.DamagePlayer(damage); } } if (collision.GetComponent <TNT>() != null) { TNT tnt = collision.GetComponent <TNT>(); if (tnt != null && !tnt.hasExploded) { //tnt.Detonate(true); tnt.StartTimer(); } } }
private void OnCollisionEnter2D(Collision2D collision) { CustomPlayerController player = collision.gameObject.GetComponent <CustomPlayerController>(); if (player != null) { if (!player.hitSpikeWall) { player.hitSpikeWall = !player.hitSpikeWall; player.DamagePlayer(player.curPlayerHealth); player.RB.AddForce(Vector2.up * upForce, ForceMode2D.Impulse); } } }