//Deals with removing health, activating damage animations, and checking if dead then trigger death private void TakeDamage(Damage damage, bool triggerAnimation) { if (damage.DamageValue < 0) { damage.DamageValue = 0; } characterStats.decreaseHealth(damage.DamageValue); //Create a UI Damage Pop up DamagePopUpController.CreateDamagePopUp(damage.DamageValue.ToString(), new Vector2(transform.position.x + ThisCollider.bounds.size.x / 4.0f, transform.position.y + ThisCollider.bounds.size.y / 2.0f), damage.IsCrit, damage.damageType); if (triggerAnimation) { if (ThisAnimator != null) { ThisAnimator.SetTrigger("damage"); // play hit audio if (gameObject.tag == "Player") { gameObject.GetComponent <PlayerControllerScript> ().playHitSound(); } else if (gameObject.tag == "Enemy") { gameObject.GetComponent <Enemy> ().playHitSound(); } } } if (IsDead()) { Die(); } }
protected void Die() { if (ThisAnimator != null) { ThisAnimator.SetTrigger("death"); if (gameObject.tag == "Player") { gameObject.GetComponent <PlayerControllerScript>().Restart(); } //Destroy After animation length AnimatorClipInfo[] clipInfo = ThisAnimator.GetCurrentAnimatorClipInfo(0); int index = -1; for (int i = 0; i < clipInfo.Length; i++) { if (clipInfo[i].clip.name == "die") { index = i; } } if (index != -1) { DeleteCharacter(clipInfo[index].clip.length); } } else { //If has no death animation then just destroy the object DeleteCharacter(0.0f); } }
void attack() { if (Input.GetMouseButtonDown(0)) // left click { string nextAttack = getNextAttack(); if (nextAttack == "attack1" || nextAttack == "attack3" || nextAttack == "attack4" || nextAttack == "attack6") { audioSource1.Stop(); audioSource1.clip = clips [0]; audioSource1.Play(); // //playSounds (); } else if (nextAttack == "attack2" || nextAttack == "attack5") { audioSource1.Stop(); audioSource1.clip = clips [1]; audioSource1.Play(); } if (PlayerState != PlayerState.Demon) { ThisAnimator.SetTrigger(nextAttack); } else { ThisAnimator.SetTrigger("DemonMelee"); } IsAttacking = true; } }
void dodge() { if (GetComponent <PlayerScript>().getGrounded() == true) { if (Input.GetKey(KeyCode.LeftAlt) && characterStats.Stamina >= dodgeCost) { ThisAnimator.SetTrigger("dodge"); base.characterStats.decreaseStamina(dodgeCost); rigidBody.velocity = new Vector2(0, 0); SetFacingDirection(); if (isFacingRight) { rigidBody.AddForce(new Vector2(dodgeForce, 0)); } else { rigidBody.AddForce(new Vector2(-dodgeForce, 0)); } IsDodging = true; } } }
public void EnableBlock() { ThisAnimator.SetTrigger("initialBlock"); setIsBlocking(true); shield.GetComponent <BoxCollider2D>().enabled = true; }