Ejemplo n.º 1
0
    public void TakeHealth(float damage)
    {
        health -= damage;

        if (health <= 0)
        {
            if (SayImDead != null)
            {
                SayImDead(this);
            }
            health = startHealth;
            if (OnSwitchedOff != null)
            {
                OnSwitchedOff(this.transform);
            }
        }
        else
        {
            healthBar.gameObject.SetActive(true);
            healthBar.SetHealthBar(health / startHealth);
            if (!coroutineStarted)
            {
                coroutineStarted = true;
                StartCoroutine(SwitchOffHealthBar());
            }
        }
    }
Ejemplo n.º 2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        Collisions = Collisions + 1;
        Health enemy = collision.GetComponent <Health>();

        if (enemy)
        {
            enemy.TakeHealth(enemy.StartHealth);
        }
        float normalizedDamage = (health - Collisions) / health;


        healthBar.SetHealthBar(normalizedDamage);
        if (Collisions >= 5)
        {
            if (gameOver != null)
            {
                gameOver(this);
            }
            SceneManager.LoadScene(4);
        }
    }