IEnumerator Walk() { // Run continuously while (!Ragdoll) { // Try moving one leg do { leftLeg.TryWalk(Random.Range(moveDuration - 0.1f, moveDuration + 0.1f)); yield return(null); // Stay in this loop while this leg is moving. } while (leftLeg.isMoving); // Do the same thing for the other leg do { rightLeg.TryWalk(Random.Range(moveDuration - 0.1f, moveDuration + 0.1f)); yield return(null); } while (rightLeg.isMoving); } }