// Checks with collision between different items. private void OnTriggerEnter2D(Collider2D other) { // Moves player down if (other.tag == "Door1") { this.gameObject.transform.position += new Vector3(0, -upPlayer, 0); Down = true; finalPos += new Vector3(0, -upCamera, 0); } // Moves player up else if (other.tag == "Door2") { this.gameObject.transform.position += new Vector3(0, upPlayer, 0); Up = true; finalPos += new Vector3(0, upCamera, 0); } // Moves player left else if (other.tag == "Door3") { this.gameObject.transform.position += new Vector3(-sidePlayer, 0, 0); Left = true; finalPos += new Vector3(-sideCamera, 0, 0); } // Moves player right else if (other.tag == "Door4") { this.gameObject.transform.position += new Vector3(sidePlayer, 0, 0); Right = true; finalPos += new Vector3(sideCamera, 0, 0); } // Resets level else if (other.tag == "StairDown") { stairDown = true; StartCoroutine(Fade1()); FadeAway.gameObject.SetActive(true); } // Checks Collision with Enemy else if ((other.tag == "Enemy" || other.tag == "shot") && CanBeHit) { Animation.SetTrigger("Hit"); AudioManager.instance.Play("PlayerHurt"); StartCoroutine(hurtTimer()); playerHitAnim.gameObject.SetActive(true); //calls the coroutine function StartCoroutine(cooldown()); //distance the player will travel var mag = 1250; //calculating the distance between both the player and enemy var force = transform.position - other.transform.position; //round up the force value force.Normalize(); //pushes the player back gameObject.GetComponent <Rigidbody2D>().AddForce(force * mag); var healthUI = GetComponent <HealthUI>(); //takes off a health value on the UI stats.TakeDamage(1); if (stats.GetTotalModdedHealth() <= 0) { //so we dont delete the player AudioManager.instance.Play("Die"); this.transform.position = new Vector3(1000f, 1000f, 1000f); playerHitAnim.SetActive(false); } } else if (other.tag == "Mud") { if (!isSlowed) { isSlowed = true; } } }