Search Unity

About regdoll and animation

Discussion in 'Animation' started by skekici, Aug 20, 2021.

  1. skekici

    skekici

    Joined:
    Jan 24, 2021
    Posts:
    30
    hello i have an enemy and when i shoot her or attack her with sword i activate her regdoll and after 2 seconds i want to turn it off again this is my code


    Code (CSharp):
    1. {
    2. public bool buul;
    3.     // Start is called before the first frame update
    4.     void Start()
    5.     {
    6.         Fiziks(true);
    7.         Colldiers(true);
    8. StartCoroutine(WaitBeforeOpen());
    9. buul=false;
    10.     }
    11.  
    12.     // Update is called once per frame
    13.     void Update()
    14.     {
    15.      
    16.     }
    17.  
    18. void Fizik(bool durum){
    19.  
    20. Rigidbody[] rg=GetComponentsInChildren<Rigidbody>();
    21. foreach(Rigidbody Fiziks in rg){
    22.  
    23. Fiziks.isKinematic=durum;
    24. }
    25.  
    26. }
    27. void Colli(bool durum){
    28.  
    29. Collider[] cl=GetComponentsInChildren<Collider>();
    30. foreach(Collider Colliders in cl){
    31.  
    32. Colliders.enabled=durum;
    33. }
    34.  
    35. }
    36.  
    37. public void OnCollisionEnter(Collision other){
    38.  
    39. if(other.gameObject.tag=="Arrow"){
    40. buul=true;
    41. GetComponent<Animation>().enabled=false;
    42. gameObject.GetComponent<NavMeshAgent>().enabled = false;
    43. Fizik(false);
    44. Colli(true);
    45.  
    46.  
    47.  
    48.  
    49.  
    50.  
    51. }
    52. }
    53. public IEnumerator WaitBeforeOpen(){
    54.   if(buul==true){
    55. yield return new WaitForSeconds(1);
    56. GetComponent<Animation>().enabled=true;
    57. }
    58. buul=false;
    59.  
    60. }
    61. }
     
    Last edited by a moderator: Aug 23, 2021