johnnygoodguy2000

Combat

Oct 18th, 2025 (edited)
575
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Combat : MonoBehaviour
  6. {
  7.    
  8.      [Header("Attack Settings")]
  9.     public int damage;
  10.     public float attackRadius = 0.5f;
  11.     public float attackCooldown = 1.5f;
  12.     public Transform attackPoint;
  13.     public LayerMask enemyLayer;
  14.  
  15.     public Player player;
  16.  
  17.     public bool CanAttack => Time.time >= nextAttackTime;
  18.     private float nextAttackTime;
  19.  
  20.  
  21.  
  22.     public void AttackAnimationFinished()
  23.     {
  24.         player.AttackAnimationFinished();
  25.     }
  26.    
  27.     public void Attack()
  28.     {
  29.         if (!CanAttack)
  30.         return;
  31.         nextAttackTime = Time.time + attackCooldown;
  32.        
  33.        Collider2D enemy = Physics2D.OverlapCircle(attackPoint.position, attackRadius, enemyLayer);
  34.             if (enemy != null)
  35.            
  36.                 enemy.gameObject.GetComponent<Health>().ChangeHealth(-damage);  
  37.     }
  38.    
  39.            
  40. }
  41.  
Tags: combat
Advertisement
Add Comment
Please, Sign In to add comment