Ejemplo n.º 1
0
    public void getDamaged(int damage, GameObject damager)
    {
        playerDamaged = true;
        Rigidbody2D body           = GetComponent <Rigidbody2D>();
        Vector2     actualPosition = body.transform.position;
        Vector2     orientation    = (actualPosition - (Vector2)damager.transform.position).normalized;

        body.AddForce(orientation * 100000);
        nextLife = Time.time + lifeCooldown;
        life.takeDamage(damage);
        if (life.getLifeLeft() <= 0)
        {
            playerAlive      = false;
            body.constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezePositionY;
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Damages pookie with a certain amount of damage by a damager.
    /// </summary>
    /// <param name="damage"></param>
    /// <param name="damager"></param>
    public void getDamaged(int damage, GameObject damager)
    {
        playerDamaged = true;
        Rigidbody2D body           = GetComponent <Rigidbody2D>();
        Collider2D  collider       = GetComponent <Collider2D>();
        Vector2     actualPosition = body.transform.position;
        Vector2     orientation    = (actualPosition - (Vector2)damager.transform.position).normalized;

        body.AddForce(orientation * 100000);
        nextLife = Time.time + lifeCooldown;
        life.takeDamage(damage);
        SoundManager.instance.playSingle(SoundManager.instance.hit);
        if (life.getLifeLeft() <= 0)
        {
            playerAlive      = false;
            body.constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezePositionY;
            collider.enabled = false;
            SoundManager.instance.playSingle(SoundManager.instance.pookieDeath);
            ButtonScript button = (ButtonScript)GameObject.FindGameObjectWithTag("Button").GetComponent <ButtonScript>();
            button.showGameOver();
        }
    }