Ejemplo n.º 1
0
    /// <summary>
    /// El enemigo sufre daño cuando la herropea colisiona con él
    /// este daño viene marcado por la variable damage
    /// </summary>
    /// <param name="damage">Daño actual que realiza le herropea</param>
    public void GetDamage(float damage)
    {
        health -= damage;
        color.CambiaColor();

        //rb.AddForce(new Vector2(impulseAfterDamageX, impulseAfterDamageY));
        if (health <= 0)
        {
            if (gameObject.GetComponent <Shield>() == null)
            {
                Instantiate(sangre, transform.position, Quaternion.identity);
                SpawnPowerUp();
                Destroy(this.gameObject);
            }
            else
            {
                gameObject.SetActive(false);
            }
        }
    }
//Metodo para restar vidas
    public void LoseHearts(int damage)
    {
        //metemos un cooldown de inmunidad
        if (health > 0 && Time.time >= time + inmunityCooldown)
        {
            //restamos la referencia damage (editable desde el inspector) a las vidas
            health -= damage;
            color.CambiaColor();
            Debug.Log("Vidas restante del jugador " + health);
            time = Time.time;
            for (int i = 0; i < damage; i++)
            {
                GameManager.GetInstance().HeartDestroyed();
            }
        }

        if (health <= 0)
        {
            GameManager.GetInstance().ActivateGameOverPanel();
        }
    }