示例#1
0
    public void Heal(int amount)
    {
        int newAmount = amount;

        if (isDead)
        {
            currentHeart.gameObject.SetActive(true);
            newAmount = currentHeart.AddHealth(newAmount);
            if (newAmount <= 0)
            {
                return;
            }
        }

        for (; newAmount > 0;)
        {
            newAmount = currentHeart.AddHealth(amount);
            if (newAmount > 0 && activeHeart < maxHearts - 1)
            {
                activeHeart += 1;
                hearts[activeHeart].SetActive(true);
                currentHeart = hearts[activeHeart].GetComponent <HealthBar>();
            }
            else
            {
                return;
            }
        }
    }
示例#2
0
    //collision with the healthpack
    private void OnTriggerEnter(Collider other)
    {
        //make sure the collision is with the player
        if (other.tag == "Player")
        {
            currHealth.AddHealth();             //go to the add health function in HealthBar

            Destroy(this.gameObject);           //destroy the healthpack
        }
    }
示例#3
0
    public int bonusAmount = 10; // Value for bonuses.

    // Checks collision between body and bonuses object.
    private void OnTriggerEnter2D(Collider2D collision)
    {
        Destroy destroy = collision.gameObject.GetComponent <Destroy>();

        health = FindObjectOfType <HealthBar>();

        // If bonus was picked then increase health bar.
        if (collision.gameObject.CompareTag("Bonus"))
        {
            //Debug.Log("Picked Up");

            destroy.GetComponent <Destroy>().Kill();
            //health.showHealth();
            health.AddHealth(10);
        }
    } // End of OnTriggerEnter2D method
 public void AddHealth(int health)
 {
     healthBar.AddHealth(health);
 }