public void ModifyHealth(int health, bool instantRespawn = false) { // only do damage if we are not invincible (can still respawn on instantRespawn damaging objects, just without taking damage) if (!_isinvinisible) { _currentHealth += health; // uppdate healthbar UIManager.GetInstance.healthBar.ModifyHealthbar(_currentHealth, _maxHealth); } // if health is 0 player is dead, else check if instantrespawn is true and respawn player to last respawn point (spikes etc can do 1 damage but will return player to begining of room) if (_currentHealth <= 0) { Die(); } else if (instantRespawn) { // dont want to be abble to take damage while respawning(will be set back when respawning is done) _isinvinisible = true; _playerRespawn.RespawnPlayer(); } else if (!_isinvinisible) // if we are not dead and instant respawn is false, do a knockback and start invinsible routines { Knockback(); StartCoroutine(Invinsible()); StartCoroutine(InvinisbleEffect()); } }
private void OnTriggerEnter2D(Collider2D other) { // Use stairs if (other.gameObject.tag == "StairTriggerArea" || other.gameObject.tag == "StairTriggerTop") { _thisStairCollider = other.transform.parent.Find("StairCollider").GetComponent <Collider2D>(); if (other.gameObject.tag == "StairTriggerArea") { isOnStairs = true; } if (other.gameObject.tag == "StairTriggerTop") { _thisStairCollider.enabled = true; isOnStairs = true; } } // Take damage from projectiles if (other.gameObject.tag == "Red" || other.gameObject.tag == "Blue") { _playerHealth.TakeDamage(1); Destroy(other.gameObject); } // Take damgae from enemies if (other.gameObject.tag == "Enemy") { //Debug.Log("KNOVKBACKS"); // knockback to the left if (transform.position.x < other.transform.position.x) { _playerMovement.Knockback(-1); } // knockback to the right if (transform.position.x > other.transform.position.x) { _playerMovement.Knockback(1); } _playerHealth.TakeDamage(1); } // Activate checkpoints and set new respawn location if (other.gameObject.tag == "Respawn") { _playerRespawn.SetActiveCheckpoint(other.gameObject); } // Respawn player if killed by deathZone if (other.gameObject.tag == "KillZone") { _playerRespawn.RespawnPlayer(); } }