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 Awake() { if (instance != null && instance != this) { Destroy(this); } else { instance = this; } }
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); } } }
private void HandleIntroQuip() { if (IntroQuipActive) { if (Input.anyKeyDown) { CustomPlayerController player = FindObjectOfType <CustomPlayerController>(); if (player != null) { if (!player.enabled) { player.RB.constraints = RigidbodyConstraints2D.FreezeRotation; player.enabled = true; } } else { Debug.Log("Player is null."); } IntroQuipActive = false; ToggleIntroQuip(IntroQuipActive); } } }