void Start ()
{
StartCoroutine(delay());
GoBall();
}
IEnumerator delay()
{
yield return new WaitForSeconds(2.5f);
print("Ok");
}
void GoBall()
{
int randomNum = Random.Range(0, 1);
if (randomNum <= .5)
rigidbody2D.AddForce(new Vector2(ballSpeed, 10));
else
rigidbody2D.AddForce(new Vector2(-ballSpeed, -10));
}
I cannot get WaitForSeconds to work in Unity at all.
I’ve made sure my function returns an IEnumerator.
I’ve started up the function with StartCoroutine(), but no luck.
My ball keeps launching without any delay.