using System; using UnityEngine; // ReSharper disable once CheckNamespace namespace BlueWaterProject { public class CloseWeapon : MonoBehaviour { #region Property and variable private bool isAttacked; private EAiType attackerAiType; private AiStat attackerStat; private bool isInit; private bool canAttack; #endregion #region Unity built-in function private void OnTriggerEnter(Collider other) { if (!isInit || !canAttack || isAttacked) return; if (other.gameObject.layer == LayerMask.NameToLayer("HitBox")) { switch (attackerAiType) { case EAiType.NONE: print("attackerAiType == NONE Error"); break; case EAiType.PLAYER: case EAiType.PIRATE: if (other.gameObject.CompareTag("Enemy")) { break; } return; case EAiType.ENEMY: if (other.gameObject.CompareTag("Pirate") || other.gameObject.CompareTag("Player")) { break; } return; default: throw new ArgumentOutOfRangeException(); } var iDamageable = other.GetComponentInParent(); iDamageable.TakeDamage(attackerStat.Atk, attackerStat.ShieldPenetrationRate); isAttacked = true; } } #endregion #region Custom function public void SetBoxCollider() { var col = GetComponent(); if (col) { col.isTrigger = true; isInit = true; return; } var boxCollider = gameObject.AddComponent(); boxCollider.isTrigger = true; isInit = true; } public void SetIsAttacked(bool value) => isAttacked = value; public void SetAttackerAiType(EAiType value) => attackerAiType = value; public void SetAttackerStat(AiStat value) => attackerStat = value; public void SetCanAttack(bool value) => canAttack = value; #endregion } }