//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()); } } }
//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(); } }