private void Update() { targetTime -= Time.deltaTime; clockTime -= Time.deltaTime; if (clockTime <= 0.0f) { UIMgr.AddTimer(1); clockTime = 1.0f; } //the healthbar lose life test if (HealthBarHandler.GetHealthBarValue() == 0f) { // SceneManager.LoadScene(2); Debug.Log("se murio por vida"); } if (Input.GetButton("Fire1") && Time.time > nextdisparo) { nextdisparo = Time.time + veldisparo + 1; Instantiate(disparo, lugardisparo.position, lugardisparo.rotation); } Movement(); }
void Update() { float moveHorizontal = Input.GetAxis("Horizontal") * moveSpeed; float moveVertical = Input.GetAxis("Vertical") * moveSpeed; rb.velocity = new Vector2(moveHorizontal, moveVertical); if (Input.GetMouseButton(0) && Time.time > nextFire) { Vector2 target = Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y)); Vector2 myPos = new Vector2(transform.position.x, transform.position.y); Vector2 direction = target - myPos; direction.Normalize(); Quaternion rotation = Quaternion.Euler(0, 0, Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg + -90f); Instantiate(projectile, transform.position, rotation); nextFire = Time.time + cooldown; } else if (Input.GetKeyDown("space") && Time.time > nextSpecialFire) { Vector2 target = Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y)); Vector2 myPos = new Vector2(transform.position.x, transform.position.y); Vector2 direction = target - myPos; direction.Normalize(); Quaternion rotation = Quaternion.Euler(0, 0, Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg + -90f); Instantiate(specialProjectile, transform.position, rotation); nextSpecialFire = Time.time + specialCooldown; } if (HealthBarHandler.GetHealthBarValue() <= 0) { youDied.enabled = true; gameObject.SetActive(false); } }
/* * private void FixedUpdate() * { * float moveHorizontal = Input.GetAxis("Horizontal"); * float moveVertical = Input.GetAxis("Vertical"); * * Vector2 movement = new Vector2(moveHorizontal, moveVertical); * * rb.AddForce(movement * speed); * } */ private void OnCollisionEnter2D(Collision2D collision) { HealthBarHandler.SetHealthBarValue(HealthBarHandler.GetHealthBarValue() - 0.1f); if (HealthBarHandler.GetHealthBarValue() <= 0) { Destroy(gameObject); } }
public void TakeDamage(float damageAmount) { health -= damageAmount; HealthBarHandler.SetHealthBarValue(HealthBarHandler.GetHealthBarValue() - damageAmount); Debug.Log(gameObject.name + " health = " + health); if (health <= 0) { Die(); } }
private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Enemy" || collision.gameObject.tag == "Boss") { HealthBarHandler.SetHealthBarValue(HealthBarHandler.GetHealthBarValue() - 0.05f); } if (collision.gameObject.tag == "heart") { HealthBarHandler.SetHealthBarValue(HealthBarHandler.GetHealthBarValue() + 0.2f); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag == "Wall") { Destroy(gameObject); } if (collision.gameObject.tag == "Player") { Destroy(gameObject); HealthBarHandler.SetHealthBarValue(HealthBarHandler.GetHealthBarValue() - 0.1f); } }
void Start() { rb = GetComponent <Rigidbody2D>(); Scene currentScene = SceneManager.GetActiveScene(); string sceneName = currentScene.name; if (sceneName == "Scene1") { HealthBarHandler.SetHealthBarValue(1); } else if (sceneName == "BossScene") { HealthBarHandler.SetHealthBarValue(HealthBarHandler.GetHealthBarValue()); } }
private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Enemy" || collision.gameObject.tag == "Boss") { HealthBarHandler.SetHealthBarValue(HealthBarHandler.GetHealthBarValue() - 0.1f); } if (HealthBarHandler.GetHealthBarValue() <= 0) { youDied.enabled = true; Destroy(gameObject); } if (collision.gameObject.tag == "BossRoom") { SceneManager.LoadScene(sceneName: "BossScene"); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag == "topWall") { Destroy(this.gameObject); } else if (collision.gameObject.tag == "disparo") { if (GetComponent <SpriteRenderer>().sprite == balloonSprites[0]) { UIMgr.AddScore(10); HealthBarHandler.SetHealthBarValue(HealthBarHandler.GetHealthBarValue() + 0.10f); } else { UIMgr.AddScore(1); HealthBarHandler.SetHealthBarValue(HealthBarHandler.GetHealthBarValue() + 0.01f); } Destroy(this.gameObject); Destroy(collision.gameObject); } }
// Update is called once per frame void Update() { HealthBarHandler.SetHealthBarValue(HealthBarHandler.GetHealthBarValue() - 0.001f); }
void timerEnded() { HealthBarHandler.SetHealthBarValue(HealthBarHandler.GetHealthBarValue() - 0.02f); UIMgr.AddScore(-5); //targetTime = 50f; }