64 lines
1.8 KiB
C#
64 lines
1.8 KiB
C#
|
using System;
|
||
|
using UnityEngine;
|
||
|
|
||
|
// ReSharper disable once CheckNamespace
|
||
|
namespace BlueWaterProject
|
||
|
{
|
||
|
public class MeleeWeapon : MonoBehaviour
|
||
|
{
|
||
|
#region Property and variable
|
||
|
|
||
|
private bool isAttacked;
|
||
|
|
||
|
private AttackerType attackerType;
|
||
|
private AiStat attackerStat;
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region Unity built-in function
|
||
|
|
||
|
private void OnTriggerEnter(Collider other)
|
||
|
{
|
||
|
if (isAttacked) return;
|
||
|
|
||
|
if (other.gameObject.layer == LayerMask.NameToLayer("HitBox"))
|
||
|
{
|
||
|
switch (attackerType)
|
||
|
{
|
||
|
case AttackerType.NONE:
|
||
|
break;
|
||
|
case AttackerType.OFFENSE:
|
||
|
if (!other.gameObject.CompareTag("Enemy") && !other.gameObject.CompareTag("House"))
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
break;
|
||
|
case AttackerType.DEFENSE:
|
||
|
if (!other.gameObject.CompareTag("Player") && !other.gameObject.CompareTag("Pirate"))
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
break;
|
||
|
default:
|
||
|
throw new ArgumentOutOfRangeException();
|
||
|
}
|
||
|
|
||
|
var iDamageable = other.GetComponentInParent<IDamageable>();
|
||
|
|
||
|
iDamageable.TakeDamage(attackerStat, iDamageable.AiStat);
|
||
|
|
||
|
isAttacked = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region Custom function
|
||
|
|
||
|
public void SetIsAttacked(bool value) => isAttacked = value;
|
||
|
public void SetAttackerType(AttackerType value) => attackerType = value;
|
||
|
public void SetAttackerStat(AiStat value) => attackerStat = value;
|
||
|
|
||
|
#endregion
|
||
|
}
|
||
|
}
|