JojikYT

HealthSystem

May 15th, 2022
2,613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.91 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class HealthSystem : MonoBehaviour
  6. {
  7.     [SerializeField] float health = 100;
  8.     [SerializeField] GameObject hitVFX;
  9.     [SerializeField] GameObject ragdoll;
  10.  
  11.     Animator animator;
  12.     void Start()
  13.     {
  14.         animator = GetComponent<Animator>();
  15.     }
  16.  
  17.     public void TakeDamage(float damageAmount)
  18.     {
  19.         health -= damageAmount;
  20.         animator.SetTrigger("damage");
  21.         CameraShake.Instance.ShakeCamera(2f, 0.2f);
  22.  
  23.         if (health <= 0)
  24.         {
  25.             Die();
  26.         }
  27.     }
  28.  
  29.     void Die()
  30.     {
  31.         Instantiate(ragdoll, transform.position, transform.rotation);
  32.         Destroy(this.gameObject);
  33.     }
  34.     public void HitVFX(Vector3 hitPosition)
  35.     {
  36.         GameObject hit = Instantiate(hitVFX, hitPosition, Quaternion.identity);
  37.         Destroy(hit, 3f);
  38.  
  39.     }
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment