Falling blocks! (Answered)

I just started with unity not too long ago.
I want to set up a block that, after the player has touched, it will drop in 3 seconds.
I have a cube set up with a box collider and a rigidbody (nothing checked) and a childed empty game object with a box collider set to “is trigger” and a script as follows.


using UnityEngine;
using System.Collections;

public class FallingCube : MonoBehaviour {
	
	// Use this for initialization
	void Start () {}
	
	// Update is called once per frame
	void Update () {}
	
	IEnumerable OnCollision(){
		Debug.Log("Collision", this);
		yield return new WaitForSeconds(3.0f);
		StartCoroutine("CubeFalling");
	}	
	
	IEnumerable OnTriggerEnter(){
		Debug.Log("Trigger", this);
		yield return new WaitForSeconds(3.0f);
		StartCoroutine("CubeFalling");
	}
	
	void CubeFalling(){
		transform.parent.rigidbody.useGravity = true;
	}
}

I just can’t figure out how to set it up properly…

//UPDATE
The trigger is firing, now that I have replaced the IEnumerable with void and removed the wait. For some reason the trigger will not call the other function. So, I put the gravity on code inside the OnTrigger. Now, it’s triggering on start of the game…

I think you got mixed up between your methods. This is tested and works.

	IEnumerator CubeFalling ()
	{
		yield return new WaitForSeconds(3.0f);
		transform.parent.rigidbody.useGravity = true;
		// You could also call your method here and delete the line above
		// CubeFall();
	}
	
	void OnCollisionEnter (Collision col)
	{
		Debug.Log("Hit");
		StartCoroutine ("CubeFalling");
	}
	
	// Optional
	void CubeFall ()
	{
		transform.parent.rigidbody.useGravity = true;
	}

OnCollisionEnter will not work in this case, because the collider is a trigger. OnTriggerEnter should work, but the character must be a CharacterController or Rigidbody (even a kinematic rigidbody). Check also the trigger size: it must be larger than the cube, or its collider will stop the character before the trigger detect it.

//UPDATE 2: FIXED! All working!

**IEnumerable instead of IEnumerator!!


using UnityEngine;
using System.Collections;

public class FallingCube : MonoBehaviour {
	
	// Use this for initialization
	void Start () {
		//Debug.Log("Start!", this);	
	}
	
	// Update is called once per frame
	void Update () {}
	
	void OnTriggerEnter(Collider other){
		//did the player's robot trigger it?
		if(other.transform.root.gameObject.name == "Robot00"){
			StartCoroutine(CubeFalling());
		}
	}
	
	IEnumerator CubeFalling(){
		yield return new WaitForSeconds(3.0f);
		//Debug.Log("wait", this);
		transform.parent.rigidbody.useGravity = true;
		transform.parent.rigidbody.isKinematic = false;
		//Debug.Log("done", this);
	}
}