shadowx320

EnemyStats

Apr 8th, 2021
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. namespace SG
  6. {
  7.     public class EnemyStats : MonoBehaviour
  8.     {
  9.         public int healthLevel = 10;
  10.         public int maxHealth;
  11.         public int currentHealth;
  12.  
  13.         Animator animator;
  14.  
  15.         private void Awake()
  16.         {
  17.             animator = GetComponentInChildren<Animator>();
  18.         }
  19.  
  20.         void Start()
  21.         {
  22.             maxHealth = SetMaxHealthFromHealthLevel();
  23.             currentHealth = maxHealth;
  24.         }
  25.  
  26.         private int SetMaxHealthFromHealthLevel()
  27.         {
  28.             maxHealth = healthLevel * 10;
  29.             return maxHealth;
  30.         }
  31.  
  32.         public void TakeDamage(int damage)
  33.         {
  34.             currentHealth = currentHealth - damage;
  35.  
  36.             animator.Play("Damage_01");
  37.  
  38.             if (currentHealth <= 0)
  39.             {
  40.                 currentHealth = 0;
  41.                 animator.Play("Dead_01");
  42.                 // Handle Player Death
  43.  
  44.             }
  45.         }
  46.     }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment