private Tween HideActiveMenu(GameObject targetMenu) { Sequence hideSeq = DOTween.Sequence(); GameObject oldMenu = activeMenu; float topY = menuElements[oldMenu].Select(canvasGroup => canvasGroup.transform.position.y).Max(); if (oldMenu != optionsMenu && targetMenu == optionsMenu) { topY = title.transform.position.y; hideSeq.Insert(0, title.transform.DOPunchScale(Vector3.one * pulseMagnitude, fadeDuration, 0, 0)); hideSeq.Insert(fadeDuration / 2, title.DOFade(0, fadeDuration / 2)); hideSeq.AppendCallback(() => title.DeactivateObject()); } float baseLength = hideSeq.Duration(); foreach (CanvasGroup uiElement in menuElements[oldMenu]) { float delay = (topY - uiElement.transform.position.y) * delayFactor; hideSeq.Insert(baseLength + delay, uiElement.transform.DOPunchScale(Vector3.one * pulseMagnitude, fadeDuration, 0, 0)); hideSeq.Insert(baseLength + delay + fadeDuration / 2, uiElement.DOFade(0, fadeDuration / 2)); } hideSeq.AppendCallback(() => oldMenu.Deactivate()); return(hideSeq); }