public void OnTriggerEnter(Collider other) { if (other.gameObject.layer == LayerMask.NameToLayer("EnemyAttack") && alive) { EnemyTrash trashScript = other.gameObject.GetComponentInParent <EnemyTrash>(); Attack currentAttackReceived = trashScript.GetAttack(); if (currentAttackReceived != null) { TakeDamage(currentAttackReceived.damage); } } }
public void OnTriggerEnter(Collider other) { if (other.gameObject.layer == LayerMask.NameToLayer("Interactable")) { Interactable interactable = other.gameObject.GetComponent <Interactable>(); if (interactable != null && interactable.CanInteract()) { canInteract = true; } } else if (other.gameObject.layer == LayerMask.NameToLayer("EnemyAttack")) { EnemyTrash trashScript = other.gameObject.GetComponentInParent <EnemyTrash>(); Attack currentAttackReceived = trashScript.GetAttack(); if (currentAttackReceived != null) { if (anim.GetCurrentAnimatorStateInfo(0).IsName("Damaged") == false && anim.GetCurrentAnimatorStateInfo(0).IsName("Block") == false && anim.GetCurrentAnimatorStateInfo(0).IsName("Die") == false) { SpawnHitParticles(other.gameObject.GetComponent <Collider>().ClosestPointOnBounds(transform.position)); AudioSources.instance.PlaySound((int)AudiosSoundFX.Enemy_Combat_AttackHit); TakeDamage(currentAttackReceived.damage); anim.SetTrigger("damaged"); } else if (anim.GetCurrentAnimatorStateInfo(0).IsName("Block") == true) { AudioSources.instance.PlaySound((int)AudiosSoundFX.Player_Combat_BlockAttack); } } } else if (other.gameObject.layer == LayerMask.NameToLayer("BossAttack")) { bool canReceiveBossAttack = true; if (anim.GetCurrentAnimatorStateInfo(0).IsName("Damaged") == true || anim.GetCurrentAnimatorStateInfo(0).IsName("Die") == true) { canReceiveBossAttack = false;; } else { if (other.name == "Ray") { Vector3 playerLeftForward = transform.forward - transform.right; if (anim.GetCurrentAnimatorStateInfo(0).IsName("Block") == true && Vector3.Dot(playerLeftForward, other.transform.parent.forward) < 0.2f) { AudioSources.instance.PlaySound((int)AudiosSoundFX.Player_Combat_BlockAttack); canReceiveBossAttack = false; } } if (other.name == "ArmCollider") { //hurts you anyway } } if (canReceiveBossAttack) { blocking = false; SpawnHitParticles(other.gameObject.GetComponent <Collider>().ClosestPointOnBounds(transform.position)); AudioSources.instance.PlaySound((int)AudiosSoundFX.Enemy_Combat_AttackHit); TakeDamage(30); anim.SetTrigger("damaged"); } } }