Exemplo n.º 1
0
    void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag.Equals("Player"))
        {
            //Debug.Log("Player Hit!");
            PlayerHP playerHP = collision.GetComponentInChildren <PlayerHP>();

            if (playerHP != null)
            {
                if (playerHP.GetHealth > 0)
                {
                    playerHP.ChangeHealth(-1);
                    //Debug.Log("Player HP changed");
                }
            }
            else
            {
                //Debug.Log("The player HP is null!!");
            }

            Destroy(gameObject);
        }
        else if (collision.gameObject.tag.Equals("Obstacle"))
        {
            Destroy(gameObject);
        }
    }
Exemplo n.º 2
0
    void GetHurt(Collider2D other)
    {
        PlayerHP playerHP = other.GetComponent <PlayerHP>();

        if (playerHP != null)
        {
            playerHP.ChangeHealth(attactAmount);
        }
    }
    void OnCollisionEnter2D(Collision2D collision)
    {
        PlayerHP hp = collision.gameObject.GetComponent <PlayerHP>();

        if (hp != null)
        {
            hp.ChangeHealth(-1);
        }
    }
Exemplo n.º 4
0
    // when player walks on top of fire, they get damaged
    void OnTriggerStay2D(Collider2D other)
    {
        PlayerHP playerHP = other.GetComponent <PlayerHP>();

        if (playerHP != null)
        {
            if (playerHP.health > 0)
            {
                playerHP.ChangeHealth(-1);
            }
        }
    }
Exemplo n.º 5
0
    void OnTriggerEnter2D(Collider2D other)
    {
        PlayerHP playerHP = other.GetComponent <PlayerHP>();

        if (playerHP != null)
        {
            if (playerHP.GetHealth > 0)
            {
                playerHP.ChangeHealth(attackAmount);
                // Destroy(gameObject); // destroy item used to heal
            }
        }
    }