The Greatest Game Dev To Have Ever Lived
This commit is contained in:
parent
fada3af715
commit
00e65ff31f
16 changed files with 398 additions and 37 deletions
|
|
@ -5,9 +5,10 @@ using UnityEngine;
|
|||
|
||||
public class MeleeWeapon : Weapon
|
||||
{
|
||||
public LayerMask entityLayer;
|
||||
[SerializeField] private Rigidbody2D rb;
|
||||
[SerializeField] private GameObject debugColliderHitbox;
|
||||
[SerializeField] private Vector2 colliderSize;
|
||||
[SerializeField] private List<Enemy> enemiesInRange = new();
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
|
@ -15,17 +16,14 @@ public class MeleeWeapon : Weapon
|
|||
{
|
||||
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);
|
||||
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))
|
||||
{
|
||||
RaycastHit2D[] enemyList = Physics2D.BoxCastAll(transform.position, colliderSize, Vector3.Angle(transform.position, mouseWorldPos),
|
||||
PlayerEntityMovement.instance.mouseWorldPos, 2, entityLayer);
|
||||
foreach (RaycastHit2D enemy in enemyList)
|
||||
foreach (Enemy enemy in enemiesInRange)
|
||||
{
|
||||
if (!enemy.transform.CompareTag(tag) && enemy.transform.TryGetComponent(out Entity isEntity))
|
||||
{
|
||||
isEntity.TakeDamage(damage, thisEntity);
|
||||
}
|
||||
enemy.TakeDamage(damage, thisEntity);
|
||||
}
|
||||
isAiming = false;
|
||||
thisEntity.actions--;
|
||||
|
|
@ -47,4 +45,20 @@ public class MeleeWeapon : Weapon
|
|||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue