void OnTriggerEnter2D(Collider2D collider) { Attackable target = collider.GetComponent <Attackable>(); if (target) { RaycastHit2D hit = Physics2D.Linecast(transform.position, target.transform.position); target.DealDamage(Damage.Value, hit, creator); } destructible.DestroyObject(); }
public void Attack() { if (Inventory.CurrentShield == null) { return; } if (!canAttack) { return; } Velocity.Value += LookDirection.Value * 10f; if (AttackEffect) { float angle = Mathf.Atan2(LookDirection.Value.y, LookDirection.Value.x) * Mathf.Rad2Deg; Instantiate(AttackEffect, transform.position + (Vector3)LookDirection.Value, Quaternion.Euler(0f, 0f, angle - 90)).transform.parent = transform; } float attackRadius = 0.5f; RaycastHit2D[] hits = Physics2D.CircleCastAll(transform.position, attackRadius, LookDirection.Value, (Inventory.CurrentSword.AttackRange * 1.5f) - attackRadius, AttackLayer.Value); if (hits.Length > 0) { foreach (RaycastHit2D hit in hits) { Attackable hitAttackable = hit.transform.GetComponent <Attackable>(); if (hitAttackable != null) { hitAttackable.DealDamage(Inventory.CurrentSword.Damage, hit, transform); } } } StartCoroutine(AttackCooldown()); }