Пример #1
0
 //If get damage, reverse direction
 public void getDamage(DamagePackage dmgPackage)
 {
     //if knockback contradicts with curspeed, reverse direction
     if (dmgPackage.getKnockback().x > 0 && curSpeed < 0 || dmgPackage.getKnockback().x < 0 && curSpeed > 0)
     {
         StartCoroutine(reverseDirection());
     }
 }
Пример #2
0
    //Applies damage & knockback to enemy if attacked by player
    //  Pre: dmgPackage must be in dmgPackage format (Maybe turned into a class)
    public void getDamage(DamagePackage dmgPackage)
    {
        if (!invincibilityFrame.isRunning())
        {
            //Apply damagePackage to player
            health -= dmgPackage.getDamage();
            if (health < 0)
            {
                health = 0;
            }

            StartCoroutine(applyKnockback(dmgPackage.getKnockback()));
            GetComponent <MeshRenderer>().material = recoveryMat;

            //If health is 0, end game, else do hitstun
            if (health <= 0.0f)
            {
                death();
            }
            else
            {
                StartCoroutine(Hitstun());
            }
        }
    }
Пример #3
0
    //Applies damage & knockback to enemy if attacked by player
    //  Pre: dmgPackage must be in dmgPackage format (Maybe turned into a class)
    public void getDamage(DamagePackage dmgPackage)
    {
        hitEnemy = true;
        float   dmgTaken  = dmgPackage.getDamage();
        Vector3 knockback = dmgPackage.getKnockback() * getTimeState();

        health -= dmgTaken;

        //Sets velocity to 0 if knockback.y > 0
        if (knockback.y > 0)
        {
            thisRB.velocity = Vector3.zero;
        }

        thisRB.AddForce(knockback);

        if (health <= 0.0f)
        {
            death();
        }
    }