My logic must be quite off here. Essentially, I have a loading bar, that when activated by a mouse hover, will have it's overlaying UI panel left position increase to give the loading effect. This works fine.
The problem is with reversing the UI panel left position back to its original posion (0,0) when its not activated in the second while loop. Here is my code -
IEnumerator LerpCoroutine()
{
Vector2 xyz;
float timeElapsed = 0;
float lerpDuration = 2;
Vector2 startPos = sliderOverlayRt.offsetMin;
Vector2 x = new Vector2(0, 0);
while (isActivated && timeElapsed < lerpDuration)
{
xyz = Vector2.Lerp(startPos, new Vector2(300, 0), EaseOut(timeElapsed / lerpDuration));
sliderOverlayRt.offsetMin = xyz;
timeElapsed += Time.deltaTime;
yield return null;
}
while (!isActivated && timeElapsed < lerpDuration)
{
xyz = Vector2.Lerp(sliderOverlayRt.offsetMin, new Vector2(0, 0), EaseOut(timeElapsed / lerpDuration));
sliderOverlayRt.offsetMin = xyz;
timeElapsed += Time.deltaTime;
yield return null;
}
}
For some reason, sliderOverlayRt.offsetMin is set to zero in the second while loop, thus the UI panel left position shoots right back to (0,0).
If anyone could show a better way to do this, maybe without even having to use the double while statement, that would be hugely appreciated!
TLDR - I want to get the Vector2 to lerp from (0,0) -> (0,300) if isActivated. However, if !isActivated in the middle of the lerp transition, in which case it only went from (0,0) -> (0,150), then I want it to go from (0,150) -> (0,0).
Thanks.