Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Combat : MonoBehaviour
- {
- [Header("Attack Settings")]
- public int damage;
- public float attackRadius = 0.5f;
- public float attackCooldown = 1.5f;
- public Transform attackPoint;
- public LayerMask enemyLayer;
- public Player player;
- public bool CanAttack => Time.time >= nextAttackTime;
- private float nextAttackTime;
- public void AttackAnimationFinished()
- {
- player.AttackAnimationFinished();
- }
- public void Attack()
- {
- if (!CanAttack)
- return;
- nextAttackTime = Time.time + attackCooldown;
- Collider2D enemy = Physics2D.OverlapCircle(attackPoint.position, attackRadius, enemyLayer);
- if (enemy != null)
- enemy.gameObject.GetComponent<Health>().ChangeHealth(-damage);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment