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); } }
void Start() { InvokeRepeating("timerEnded", 10.0f, 10.0f); UIMgr = GameObject.FindGameObjectWithTag("UIManager").GetComponent <UIManager>(); transform.position = new Vector3(36, 5, 1); // aparicion nave //Health bar is called HealthBarHandler.SetHealthBarValue(1); }
/* * 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); } }
private void Start() { if (BattleManager.Instance != null) { healthHandler = BattleManager.Instance.assignHealthBar(); } anim = GetComponent <Animator>(); sr = GetComponent <SpriteRenderer>(); }
public void TakeDamage(float damageAmount) { health -= damageAmount; HealthBarHandler.SetHealthBarValue(HealthBarHandler.GetHealthBarValue() - damageAmount); Debug.Log(gameObject.name + " health = " + health); if (health <= 0) { Die(); } }
private void Awake() { _bodyParts = new List <BodyPart>(); _bodyParts.Add(new BodyPart(BodyPart.BodyPartType.BODY)); _bodyParts.Add(new BodyPart(BodyPart.BodyPartType.HORN)); _bodyParts.Add(new BodyPart(BodyPart.BodyPartType.TAIL)); _healthBar = GetComponentInChildren <HealthBarHandler>(); GameManager.Instance.AddRobot(this); }
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()); } }
// Start is called before the first frame update void Start() { layerMask = 1 << 13; filter.SetLayerMask(layerMask); //to catch bugs if (fHP <= 0f) { fHP = 1f; } if (delaySeconds <= 0f) { delaySeconds = 1f; } HealthBarHandler = GetComponent <HealthBarHandler>(); HealthBarHandler.SetMaxHP(fHP); }
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"); } }
// Update is called once per frame void Update() { if (healthRegenTimer > 0) { healthRegenTimer -= Time.deltaTime; } if (healthRegenTimer <= 0 && health > 0 && isPlayer) { health += 35 * Time.deltaTime; } if (health > maxHealth) { health = maxHealth; } if (deathTimer > 0) { deathTimer -= Time.deltaTime; } if (iframes > 0) { iframes -= Time.deltaTime; } if (health <= 0 && deathTimer > 0) { doDeathAnimation(); } if (isPlayer) { float m = health; m = map(m, 0, maxHealth, 0, 1); HealthBarHandler.SetHealthBarValue(m); } if (health <= 0 && deathTimer <= 0) { die(); } }
int playersToAvoid;// = LayerMask.GetMask("Player"); // Used by Safe aiMvmt. void Start() { layerMask = (1 << 4) | (1 << 9) | (1 << 12); //layersToAvoid.layerMask = 4608;// layersToAvoid.layerMask = LayerMask.GetMask("Obstacles", "Player"); // It may be helpful to put Enemies in seperate layer or get rid of Player layer. playersToAvoid = LayerMask.GetMask("Player"); fWaitTime = fStartWaitTime; frameToCastOn = Random.Range(0, MAX_FRAMES_BETWEEN_RAYCASTS); iRandomSpot = 0; if (aiMvmt == MovementTypeEnum.None) { FillMoveSpots(); aiMvmt = MovementTypeEnum.Patrol; } rb = GetComponent <Rigidbody2D>(); HealthBarHandler = GetComponent <HealthBarHandler>(); HealthBarHandler.SetMaxHP(fHP); feetAnimation = transform.GetChild(2).GetComponent <Animator>(); }
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); } }
void Awake() { Instance = this; }
void Start() { HealthBarHandler.SetHealthBarValue(1.0f); }
// 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; }
//private Rigidbody2D rb; private void Start() { //rb = GetComponent<Rigidbody2D>(); HealthBarHandler.SetHealthBarValue(1); }