using System; using System.Collections.Generic; using Core.Extensions; using UnityEngine; public class MeleeWeapon : Weapon { [SerializeField] private Rigidbody2D rb; [SerializeField] private GameObject debugColliderHitbox; [SerializeField] private Vector2 colliderSize; [SerializeField] private List enemiesInRange = new(); 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); Vector2 direction = mouseWorldPos - (Vector2)transform.position; float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; //did you know i sucked at trig? because i don't understand this lol ; rb.rotation = angle; if (Input.GetMouseButtonDown(0)) { foreach (Enemy enemy in enemiesInRange) { enemy.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; } private void OnTriggerEnter2D(Collider2D other) { if (!other.CompareTag(tag) && other.TryGetComponent(out Enemy isEnemy)) { enemiesInRange.Add(isEnemy); } } private void OnTriggerExit2D(Collider2D other) { if (!other.CompareTag(tag) && other.TryGetComponent(out Enemy isEnemy) && enemiesInRange.Contains(isEnemy)) { enemiesInRange.Remove(isEnemy); } } }