using System; using UnityEngine; // ReSharper disable once CheckNamespace namespace BlueWaterProject { public class CloseWeapon : MonoBehaviour { #region Property and variable private bool isAttacked; private bool isOffense; private EAiType attackerAiType; private float atk; private float shieldPenetrationRate; 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(atk); isAttacked = true; } else if (other.gameObject.layer == LayerMask.NameToLayer("Props")) { if (!isOffense) return; if (other.gameObject.CompareTag("House") || other.gameObject.CompareTag("Tower")) { var iDamageable = other.GetComponentInParent(); iDamageable.TakeDamage(atk); 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 SetWeaponStat(float atkStat, float shieldPenetrationRateStat, bool isOffense) { atk = atkStat; shieldPenetrationRate = shieldPenetrationRateStat; this.isOffense = isOffense; } public void SetIsAttacked(bool value) => isAttacked = value; public void SetAttackerAiType(EAiType value) => attackerAiType = value; public void SetCanAttack(bool value) => canAttack = value; #endregion } }