Disable Ragdoll #C - Timer before disable.

So I am a beginning coder who has been writing in Javascript up until this point, but what I am doing now is creating a short script that disables the ragdoll effect after the enemy has died. I am using a custom method that is a part of the asset pack we are using - Paragon AI (I think now called Tactical Shooter AI or something).

I have followed the instructions of the author who told me how I could go about disabling the effect via turning off the colliders of the object and setting the rigidbody to kinematic which works; however the enemy just freezes as soon as they die so they are not dropping to the ground. So I figure I need a short timer that runs through before the rest of the code, so that the bodies have time to hit the ground before the ragdolls are disabled.

Here’s my code.

using UnityEngine;
using System.Collections;


public class disableRagdoll : MonoBehaviour {
	Collider[] rigColliders;
	Rigidbody[] rigRigidbodies;

	void Start (){
		rigColliders = GetComponentsInChildren<Collider>();
		rigRigidbodies = GetComponentsInChildren<Rigidbody>();
	}

	public void OnAIDeath()
	{
		//wait 2-3 seconds.
		foreach (Collider col in rigColliders){
			col.enabled = false;
		}

		foreach (Rigidbody rb in rigRigidbodies){
			rb.isKinematic = true;
		}
	}
}

I have commented where I think the timer should go, is anyone able to help me out?

public void OnAIDeath()
{
//wait 2-3 seconds.
foreach (Collider col in rigColliders){
col.enabled = false;
}

       Invoke("StopBody",2.0f);
     }

void StopBody()
{
     foreach (Rigidbody rb in rigRigidbodies)
     {
             rb.isKinematic = true;
         }
}

set second as per your requirement in invoke method

So I have figured out that any script that uses the OnAIDeath method will only run the code in that method before the object destroys itself. So for example I tried calling a Coroutine from the OnAIDeath method and it does not seem to run the code in the Coroutine.

So this is where I am at now, still with no success.

    public class disableRagdoll : MonoBehaviour {
    	Collider[] rigColliders;
    	Rigidbody[] rigRigidbodies;
    	public float ragdollTime;
    
    	void Start (){
    		rigColliders = GetComponentsInChildren<Collider>();
    		rigRigidbodies = GetComponentsInChildren<Rigidbody>();
    	}
    
    	public void OnAIDeath()
    	{
    		StartCoroutine(StopRagdoll());
    	}
    
    	IEnumerator StopRagdoll (){
    		yield return new WaitForSeconds(ragdollTime);
    		foreach (Rigidbody rb in rigRigidbodies) {
    			rb.isKinematic = true;
    		}
    		foreach (Collider col in rigColliders){
    			col.enabled = false;
    		}
    	}
    }