Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class attack : MonoBehaviour
- {
- public int attackDamage = 10;
- public float attackSpeed = 2f;
- private float attackTimer = 0f;
- private void Start()
- {
- attackTimer = attackSpeed;
- }
- private void Update()
- {
- attackTimer += Time.deltaTime;
- }
- private void OnTriggerStay(Collider other)
- {
- var health = other.gameObject.GetComponent<health>();
- if (health != null && attackTimer > attackSpeed)
- {
- health.sendDamage(attackDamage);
- attackTimer = 0f;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment