Hi
I’m trying to implement a simple wait for a couple of seconds after an action but it doesn’t seem to wait at all. Basically I have some disabled colliders around a box at first and after I jump on it I want to enable the colliders but wait a couple of seconds so the AddForce can work. Code below.
void OnMouseDown() // I've also tried IEnumerator OnMouseDown() - same result
{
if (action1.text == "Jump On Box")
{
player.GetComponent<Rigidbody2D().AddForce
((theBox.transform.position - player.transform.position).normalized * 250.0f);
//the add force normally works, but with the boxcolliders enabled below
//the code gets executed too quickly so my player collides BEFORE
//having the required result from add force - thus why i need the wait
StartCoroutine(Wait(3.0f)); // doesn't wait, goes directly to next line
boxCollider1.enabled = true;
boxCollider2.enabled = true;
boxCollider3.enabled = true;
boxCollider4.enabled = true;
}
}
IEnumerator Wait(float waitTime)
{
yield return new WaitForSeconds (waitTime);
}
Hope it makes sense. Thank you!