20226.01.29 수정 (공격, 피격, 아이템 드랍 및 획득 구현 완료, 히트박스 트리거 버그 수정완) 다음 작업 : 공중몬스터 구현, 태그 스킬 구현
64 lines
1.6 KiB
C#
64 lines
1.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
public class WeaponHitbox : MonoBehaviour
|
|
{
|
|
private BoxCollider2D col;
|
|
private WeaponStat _stat;
|
|
|
|
private string atktype;
|
|
|
|
//이번 공격에서 이미 때린 적들의 ID를 저장하는 리스트
|
|
private HashSet<int> hitEnemies = new HashSet<int>();
|
|
|
|
void Awake()
|
|
{
|
|
col = GetComponent<BoxCollider2D>();
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
hitEnemies.Clear();
|
|
}
|
|
|
|
public void Setup(WeaponStat stat, string atkType)
|
|
{
|
|
_stat = stat;
|
|
|
|
if (atkType == "SAtk") // 약공격
|
|
{
|
|
col.size = stat.data.sboxSize;
|
|
col.offset = stat.data.sboxOffset;
|
|
}
|
|
else if (atkType == "AAtk") // 강공격
|
|
{
|
|
col.size = stat.data.aboxSize;
|
|
col.offset = stat.data.aboxOffset;
|
|
}
|
|
atktype = atkType;
|
|
}
|
|
|
|
private void OnTriggerEnter2D(Collider2D other)
|
|
{
|
|
if (other.CompareTag("Enemy"))
|
|
{
|
|
int enemyID = other.gameObject.GetInstanceID();
|
|
if (hitEnemies.Contains(enemyID)) return;
|
|
|
|
hitEnemies.Add(enemyID);
|
|
|
|
Mob enemy = other.GetComponent<Mob>();
|
|
|
|
if (enemy != null && atktype == "SAtk")
|
|
{
|
|
enemy.TakeDamage(_stat.data.sDamage, _stat.data.hitStunTime, transform.position);
|
|
}
|
|
|
|
else if (enemy != null && atktype == "AAtk")
|
|
{
|
|
enemy.TakeDamage(_stat.data.aDamage, _stat.data.hitStunTime, transform.position);
|
|
}
|
|
}
|
|
}
|
|
} |