50 lines
1.9 KiB
C#
50 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Core.Extensions;
|
|
using UnityEngine;
|
|
|
|
public class MeleeWeapon : Weapon
|
|
{
|
|
public LayerMask entityLayer;
|
|
[SerializeField] private GameObject debugColliderHitbox;
|
|
[SerializeField] private Vector2 colliderSize;
|
|
|
|
private void Update()
|
|
{
|
|
if (isAiming)
|
|
{
|
|
Vector2 mouseWorldPos = PlayerEntityMovement.instance.mouseWorldPos; //using this so i don't have to paste in and recalculate the variable on something i already have lol
|
|
debugColliderHitbox.gameObject.SetActive(true);
|
|
transform.Lookat2D(mouseWorldPos);
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
RaycastHit2D[] enemyList = Physics2D.BoxCastAll(transform.position, colliderSize, Vector3.Angle(transform.position, mouseWorldPos),
|
|
PlayerEntityMovement.instance.mouseWorldPos, 2, entityLayer);
|
|
foreach (RaycastHit2D enemy in enemyList)
|
|
{
|
|
if (!enemy.transform.CompareTag(tag) && enemy.transform.TryGetComponent(out Entity isEntity))
|
|
{
|
|
isEntity.TakeDamage(damage, thisEntity);
|
|
}
|
|
}
|
|
isAiming = false;
|
|
thisEntity.actions--;
|
|
TurnHandler.instance.UpdateTurns();
|
|
ActionUIHandler.instance.UpdateUI();
|
|
debugColliderHitbox.gameObject.SetActive(false);
|
|
ActionUIHandler.instance.cursorObject.SetActive(false);
|
|
}
|
|
else if (Input.GetMouseButtonDown(1))
|
|
{
|
|
isAiming = false;
|
|
debugColliderHitbox.gameObject.SetActive(false);
|
|
ActionUIHandler.instance.cursorObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override void AttackEffects()
|
|
{
|
|
isAiming = true;
|
|
}
|
|
}
|