johnnygoodguy2000

EnemyAttack.cs

Jun 15th, 2024
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.54 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Unity.VisualScripting;
  4. using UnityEngine;
  5.  
  6. public class EnemyAttack : MonoBehaviour
  7. {
  8.     [SerializeField] private float damageAmount;
  9.  
  10.     private void OnCollisionStay2D(Collision2D collision) // Added 'void' return type
  11.     {
  12.         if (collision.gameObject.GetComponent<PlayerMovement>())
  13.         {
  14.             var healthController = collision.gameObject.GetComponent<HealthController>();
  15.             healthController.TakeDamage(damageAmount);
  16.         }
  17.     }
  18. }
  19.  
Advertisement
Add Comment
Please, Sign In to add comment