Search Unity

Wired behaviour on while exit condition inside coroutine

Discussion in 'Scripting' started by Max_power1965, Jan 25, 2015.

  1. Max_power1965

    Max_power1965

    Joined:
    Oct 31, 2013
    Posts:
    127
    Hi guys,
    I have this wired problem. I have this code:

    Code (CSharp):
    1.         do {
    2.  
    3.             Debug.Log ("Actual postion: " + transform.position + "End position " + this.endJumpPos);
    4.             float distCovered = (Time.time - startJumpTime) * this.jumpSpeed;
    5.             //Converted the distance in franction
    6.             float distCoveredInFraction = distCovered / this.verticalJumpDistance;
    7.             transform.position = Vector2.Lerp(this.initialJumpPos, this.endJumpPos ,distCoveredInFraction);
    8.             yield return null;
    9.         } while (transform.position.y < this.endJumpPos.y);
    This code works very well on the unity editor, but it doesn't work on iOS device because the while exit condition it's not triggered. I found a workaround to solve this problem by change the previous code into this:
    Code (CSharp):
    1. bool endJump = false;
    2.         do {
    3.             float distCovered = (Time.time - startJumpTime) * this.jumpSpeed;
    4.             //Converted the distance in franction
    5.             float distCoveredInFraction = distCovered / this.verticalJumpDistance;
    6.             transform.position = Vector2.Lerp(this.initialJumpPos, this.endJumpPos ,distCoveredInFraction);
    7.             if (!(transform.position.y < this.endJumpPos.y)) {
    8.                 endJump = true;
    9.             }
    10.             Debug.Log ("Actual postion: " + transform.position + "End position " + this.endJumpPos);
    11.             yield return null;
    12.         } while (!endJump);
    This code works very well also on iOS, so my question is very simple. I want to understand why the while condition it's not triggered in iOS device?