IEnumerator ChangeSizeCoroutine(HorizontalSizeChanger sizeChanger, float newValue, float maxSize) { float step = maxSize * 0.01F; while (true) { yield return(new WaitForEndOfFrame()); if (!ChangeSize(sizeChanger, newValue, step)) { break; } } }
bool ChangeSize(HorizontalSizeChanger sizeChanger, float newSize, float step) { float width = sizeChanger.GetWidth(); float delta = newSize - width; if (Mathf.Abs(delta) > step) { delta *= Speed * Time.deltaTime; sizeChanger.SetWidth(width + delta); return(true); } else { sizeChanger.SetWidth(newSize); return(false); } }