//we are hit public void Hit(DamageObject d) { //check if we can get hit again if (Time.time < LastHitTime + hitThreshold) { return; } //check if we are in a hittable state if (HitableStates.Contains(playerState.currentState)) { CancelInvoke(); //camera Shake CamShake camShake = Camera.main.GetComponent <CamShake>(); if (camShake != null) { camShake.Shake(.1f); } //defend incoming attack if (playerState.currentState == UNITSTATE.DEFEND && !d.DefenceOverride && (isFacingTarget(d.inflictor) || blockAttacksFromBehind)) { Defend(d); return; } else { animator.SetAnimatorBool("Defend", false); } //we are hit UpdateHitCounter(); LastHitTime = Time.time; //show hit effect animator.ShowHitEffect(); //substract health HealthSystem hs = GetComponent <HealthSystem> (); if (hs != null) { hs.SubstractHealth(d.damage); if (hs.CurrentHp == 0) { return; } } //check for knockdown if ((hitKnockDownCount >= knockdownHitCount || !IsGrounded() || d.knockDown) && playerState.currentState != UNITSTATE.KNOCKDOWN) { hitKnockDownCount = 0; StopCoroutine("KnockDownSequence"); StartCoroutine("KnockDownSequence", d.inflictor); GlobalAudioPlayer.PlaySFXAtPosition(d.hitSFX, transform.position + Vector3.up); GlobalAudioPlayer.PlaySFXAtPosition(knockdownVoiceSFX, transform.position + Vector3.up); return; } //default hit int i = Random.Range(1, 3); animator.SetAnimatorTrigger("Hit" + i); SetVelocity(Vector3.zero); playerState.SetState(UNITSTATE.HIT); //add a small force from the impact if (isFacingTarget(d.inflictor)) { animator.AddForce(-1.5f); } else { animator.AddForce(1.5f); } //SFX GlobalAudioPlayer.PlaySFXAtPosition(d.hitSFX, transform.position + Vector3.up); GlobalAudioPlayer.PlaySFXAtPosition(hitVoiceSFX, transform.position + Vector3.up); Invoke("Ready", hitRecoveryTime); } }