study/first_study/Assets/Scripts/WeaponSc/WeaponHitbox.cs

72 lines
1.9 KiB
C#
Raw Permalink Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WeaponHitbox : MonoBehaviour
{
private BoxCollider2D col;
private WeaponStat _stat;
private string atktype;
//<2F>̹<EFBFBD> <20><><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD> <20>̹<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ID<49><44> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD> <20><><EFBFBD><EFBFBD>Ʈ
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") // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
col.size = stat.data.sboxSize;
col.offset = stat.data.sboxOffset;
}
else if (atkType == "AAtk") // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
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);
}
}
}
}