I’m trying to lerp a UI element between two locations. I also tried SmoothDamp.
public void Clicked()
{
RectTransform rect = GetComponent<RectTransform>();
if (opened)
{
start = transform.localPosition;
while(currentTime <= smoothTime)
{
currentTime += Time.deltaTime;
normalizedValue = currentTime / smoothTime;
Debug.Log(normalizedValue + "opened");
//rect.localPosition = Vector3.SmoothDamp(start, pos1, ref velocity, smoothSpeed);
rect.anchoredPosition = Vector3.Lerp(start, pos1, normalizedValue);
}
currentTime = 0;
opened = false;
}
else
{
start = transform.localPosition;
while(currentTime <= smoothTime)
{
currentTime += Time.deltaTime;
normalizedValue = currentTime / smoothTime;
Debug.Log(normalizedValue + "closed");
//rect.localPosition = Vector3.SmoothDamp(start, pos2, ref velocity, smoothSpeed);
rect.anchoredPosition = Vector3.Lerp(start, pos2, normalizedValue);
}
currentTime = 0;
opened = true;
}
}