Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class EnemyHealth : MonoBehaviour
- {
- public int Maxhealth;
- public int Currhealth;
- //private bool state;
- //
- protected Animator Anim;
- protected Rigidbody Rb;
- protected BoxCollider BoxCol;
- protected Collider[] ChildrenCol;
- protected Rigidbody[] ChildrenRb;
- //get enemy component
- void Start()
- {
- RagdollActivate(false);
- Currhealth = Maxhealth;
- }
- private void Awake()
- {
- Anim = GetComponent<Animator>();
- Rb = GetComponent<Rigidbody>();
- BoxCol = GetComponent<BoxCollider>();
- Enemy = GetComponent<Enemy>();
- }
- public void RagdollActivate(bool active)
- {
- //children
- foreach (var collider in ChildrenCol)
- collider.enabled = active;
- foreach (var rigidbody in ChildrenRb)
- {
- rigidbody.detectCollisions = active;
- rigidbody.isKinematic = !active;
- }
- Anim.enabled = !active;
- Rb.detectCollisions = !active;
- Rb.isKinematic = active;
- BoxCol.enabled = !active;
- Enemy.enabled = !active;
- ChildrenCol = GetComponentsInChildren<Collider>();
- ChildrenRb = GetComponentsInChildren<Rigidbody>();
- }
- void Update()
- {
- if(Currhealth <= 0)
- {
- Destroy(gameObject);
- }
- }
- public void HurtEnemy(int damageToGive)
- {
- Currhealth -= damageToGive;
- }
- public void SetMaxHealth()
- {
- Currhealth = Maxhealth;
- }
- private void OnCollisionEnter((Collision other) && Currhealth <= 1))
- {
- if (other.gameObject.tag == ("Bulet")) //yh with 1 l only
- {
- RagdollActivate(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement