Ledger Nano X - The secure hardware wallet
SHARE
TWEET

RagdollController

a guest Apr 6th, 2020 126 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class EnemyHealth : MonoBehaviour
  6. {
  7.     public int Maxhealth;
  8.     public int Currhealth;
  9.     //private bool state;
  10.  
  11.     //
  12.  
  13.     protected Animator Anim;
  14.     protected Rigidbody Rb;
  15.     protected BoxCollider BoxCol;
  16.  
  17.     protected Collider[] ChildrenCol;
  18.     protected Rigidbody[] ChildrenRb;
  19.  
  20.     //get enemy component
  21.  
  22.     void Start()
  23.     {
  24.         RagdollActivate(false);
  25.         Currhealth = Maxhealth;
  26.        
  27.     }
  28.  
  29.     private void Awake()
  30.     {
  31.         Anim = GetComponent<Animator>();
  32.         Rb = GetComponent<Rigidbody>();
  33.         BoxCol = GetComponent<BoxCollider>();
  34.         Enemy = GetComponent<Enemy>();
  35.     }
  36.  
  37.     public void RagdollActivate(bool active)
  38.     {
  39.         //children
  40.         foreach (var collider in ChildrenCol)
  41.             collider.enabled = active;
  42.         foreach (var rigidbody in ChildrenRb)
  43.         {
  44.             rigidbody.detectCollisions = active;
  45.             rigidbody.isKinematic = !active;
  46.         }
  47.  
  48.  
  49.         Anim.enabled = !active;
  50.         Rb.detectCollisions = !active;
  51.         Rb.isKinematic = active;
  52.         BoxCol.enabled = !active;
  53.         Enemy.enabled = !active;
  54.  
  55.         ChildrenCol = GetComponentsInChildren<Collider>();
  56.         ChildrenRb = GetComponentsInChildren<Rigidbody>();
  57.     }
  58.  
  59.     void Update()
  60.     {
  61.         if(Currhealth <= 0)
  62.         {
  63.             Destroy(gameObject);
  64.         }
  65.     }
  66.  
  67.     public void HurtEnemy(int damageToGive)
  68.     {
  69.         Currhealth -= damageToGive;
  70.     }
  71.  
  72.     public void SetMaxHealth()
  73.     {
  74.         Currhealth = Maxhealth;
  75.     }
  76.  
  77.     private void OnCollisionEnter((Collision other) && Currhealth <= 1))
  78.     {
  79.         if (other.gameObject.tag == ("Bulet")) //yh with 1 l only
  80.         {
  81.             RagdollActivate(true);
  82.         }
  83.     }
  84.  
  85. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top