Script wont run movement code in else field

I have a coroutine in a script for moving the player’s camera when the player interacts with an object so the player can click on buttons on the object.

IEnumerator Cammove(bool to)
{
    if (to == true)
    {
        start = transform.GetChild(1).position;
        for (float i = 0; i < 1; i += 0.01f)
        {
            transform.GetChild(1).position = Vector3.Lerp(transform.GetChild(1).position, item.collider.transform.GetChild(0).position, i);
            yield return new WaitForSeconds(0.01f);
        }
    }
    else
    {
        for (float i = 1; i > 1; i -= 0.01f)
        {
            transform.GetChild(1).position = Vector3.Lerp(transform.GetChild(1).position, start, i);
            yield return new WaitForSeconds(0.01f);
        }
    }
}

The bool denotes whether the player is moving the camera to the object or back in their head, the if field moves it to the object, the else field moves it back. The problem is the script will move the camera to the object fine, but after that it won’t move it back, rather just keeping it in the same place, not even changing the transform values, like it just skips the line entirely. I know it’s running the else field, it just won’t move the camera. I’ve also discovered it’s perfectly fine with moving the camera to the object again, the only thing it won’t do is run any code for changing the position inside the else field, whether it uses lerp or not. I haven’t the faintest clue what could be causing this, I’m completely thrown for a loop.

2 Answers

2

not 100% sure if this will help but i dont think forelse is a usable term, if else might be what your looking for

I don’t think this for loop will do anything. i starts at 1 and immediately does not meet the condition of i > 1. Was that supposed to be i > 0 ?