void OnCollisionStay2D(Collision2D coll) { if (coll.transform.tag == "Ground") { animator.SetBool("IsJump", false); body.drag = 10; jump = true; } if (coll.transform.tag == "Health_1") { HealthPotion_1.SetActive(false); health += 50; } if (coll.transform.tag == "Health_2") { HealthPotion_2.SetActive(false); health += 50; } if (coll.transform.tag == "Health_3") { HealthPotion_3.SetActive(false); health += 50; } if (coll.transform.tag == "Teleport") { Audio.GetComponent <AudioSource>().PlayOneShot(clip); SceneManager.LoadScene("Level_2"); } else if (coll.transform.tag == "Teleport2") { Audio.GetComponent <AudioSource>().PlayOneShot(clip); SceneManager.LoadScene("Level_3"); } else if (coll.transform.tag == "Teleport3") { Audio.GetComponent <AudioSource>().PlayOneShot(clip); SceneManager.LoadScene("Level_1"); } if (coll.transform.tag == "DeathZone") { transform.rotation = Quaternion.Euler(0, 0, 90); Health_1.SetActive(false); Health_2.SetActive(false); Health_3.SetActive(false); DeathMenu.SetActive(true); } }
void OnCollisionExit2D(Collision2D coll) { if (coll.transform.tag == "Ground") { animator.SetBool("IsJump", true); body.drag = 0; jump = false; } if (coll.transform.tag == "DeathZone") { transform.rotation = Quaternion.Euler(0, 0, 90); Health_1.SetActive(false); Health_2.SetActive(false); Health_3.SetActive(false); DeathMenu.SetActive(true); } }
void Update() { if (dataManager.data.IsAK == 0 && dataManager.data.IsGlock == 0 && dataManager.data.IsRevolver == 0) { Weapon_AK.SetActive(false); Weapon_Pistol.SetActive(true); Weapon_Revolver.SetActive(false); startTimeBtwShots = 0.3f; animator.SetBool("IsGun", true); dataManager.data.IsGlock = 1; } else if (dataManager.data.IsAK == 1) { startTimeBtwShots = 0.15f; Weapon_AK.SetActive(true); Weapon_Pistol.SetActive(false); Weapon_Revolver.SetActive(false); animator.SetBool("IsGun", true); buldmg.damage = 20; } else if (dataManager.data.IsGlock == 1) { startTimeBtwShots = 0.3f; Weapon_AK.SetActive(false); Weapon_Pistol.SetActive(true); Weapon_Revolver.SetActive(false); animator.SetBool("IsGun", true); buldmg.damage = 20; } else if (dataManager.data.IsRevolver == 1) { startTimeBtwShots = 0.5f; Weapon_AK.SetActive(false); Weapon_Pistol.SetActive(false); Weapon_Revolver.SetActive(true); animator.SetBool("IsGun", true); buldmg.damage = 50; } if (timeBtwShots <= 0) { if (fire) { Shoot(); timeBtwShots = startTimeBtwShots; } } else { timeBtwShots -= Time.deltaTime; } horizontal = joystick.Horizontal; vertical = joystick.Vertical; if (horizontal < 0) { animator.SetBool("IsRunning", true); } else if (horizontal > 0) { animator.SetBool("IsRunning", true); } else { animator.SetBool("IsRunning", false); } if (vertical > .7f && jump) { body.velocity = new Vector2(0, addForce); animator.SetTrigger("Jump"); } if (projectAxis == ProjectAxis.onlyX) { direction = new Vector2(horizontal, 0); } if (health > 50) { Health_1.SetActive(true); } if (health > 25) { Health_2.SetActive(true); } if (health > 0) { Health_3.SetActive(true); } if (health < 50) { Health_1.SetActive(false); } if (health < 25) { Health_2.SetActive(false); } if (health <= 0) { transform.rotation = Quaternion.Euler(0, 0, 90); Health_3.SetActive(false); DeathMenu.SetActive(true); } if (horizontal > 0 && !isFacingRight) { Flip(); } else if (horizontal < 0 && isFacingRight) { Flip(); } }