study/first_study/Assets/Scripts/WeaponSc/WeaponHitbox.cs
jh04010421 95c50c478a 윤지호 | LostBits 기능 구현
20226.02.05 수정 (사운드 구현)
다음 작업 : 공중몬스터 구현, 태그 스킬 구현
2026-02-05 19:56:59 +09:00

72 lines
1.9 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>();
private PlayerController playerController;
public float sGageAmount = 20;
public float aGageAmount = 30;
void Awake()
{
playerController = GetComponentInParent<PlayerController>();
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")
{
playerController.ChargeTagGauge(sGageAmount);
enemy.TakeDamage(_stat.data.sDamage, _stat.data.hitStunTime, transform.position);
}
else if (enemy != null && atktype == "AAtk")
{
playerController.ChargeTagGauge(aGageAmount);
enemy.TakeDamage(_stat.data.aDamage, _stat.data.hitStunTime, transform.position);
}
}
}
}