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…
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.