0
IEnumerator SmoothlyShiftPosition(Vector3 destination, float OverTime) {

    float startTime = 0;
    while (startTime < OverTime)
    {
        Debug.Log(startTime/OverTime + "changing: " + navigationCanvas.transform.position);
        Debug.Log("startTime : " + startTime);
        navigationCanvas.transform.position = Vector3.Lerp(navigationCanvas.transform.position, destination, startTime/OverTime);
        startTime += Time.deltaTime * 2f;
        yield return null;
    }
    navigationCanvas.transform.position = destination;
}

I have this simple code snippet which i am using to lerp my object to specfied position smoothly it work sometime correctly but not always. I logged different data and found that my startTime variable sometime becomes zero continuously. I am unable to figure why this occuring? what i am doing wrong

I am calling my coroutine like this

if (SmoothlyShiftPositionIEum != null) {
                            StopCoroutine(SmoothlyShiftPositionIEum);
                        }
                       SmoothlyShiftPositionIEum = StartCoroutine(SmoothlyShiftPosition(navCanvas, smoothPositionTime));
Muhammad Faizan Khan
  • 10,013
  • 18
  • 97
  • 186

0 Answers0