eastbayeff

Untitled

Mar 10th, 2022
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class attack : MonoBehaviour
  6. {
  7.     public int attackDamage = 10;
  8.     public float attackSpeed = 2f;
  9.     private float attackTimer = 0f;
  10.  
  11.     private void Start()
  12.     {
  13.         attackTimer = attackSpeed;
  14.     }
  15.  
  16.     private void Update()
  17.     {
  18.         attackTimer += Time.deltaTime;
  19.     }
  20.  
  21.     private void OnTriggerStay(Collider other)
  22.     {
  23.         var health = other.gameObject.GetComponent<health>();
  24.  
  25.         if (health != null && attackTimer > attackSpeed)
  26.         {
  27.                 health.sendDamage(attackDamage);
  28.                 attackTimer = 0f;
  29.         }
  30.     }
  31.  
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment