LunarInfantry/Assets/Scripts/MeleeWeapon.cs

48 lines
1.7 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, 100f, entityLayer);
foreach (RaycastHit2D enemy in enemyList)
{
if (!enemy.transform.CompareTag(tag) && enemy.transform.TryGetComponent(out Entity isEntity))
{
isEntity.TakeDamage(damage);
}
}
isAiming = false;
thisEntity.hasAttacked = true;
TurnHandler.instance.UpdateTurns();
ActionUIHandler.instance.UpdateUI();
debugColliderHitbox.gameObject.SetActive(false);
}
else if (Input.GetMouseButtonDown(1))
{
isAiming = false;
debugColliderHitbox.gameObject.SetActive(false);
}
}
}
protected override void AttackEffects()
{
isAiming = true;
}
}