IEnumerator AnimateRevealRoutine(float startDelay, float showSpeedInSeconds) { // flag button state to be revealed, at first IsRevealed = false; float currentAlpha = 0; _canvasGroup.alpha = 0; // x offset data float animStartXPos = _startXPos - _xAnimOffset; float animEndXPos = _startXPos; float currentXPos = animStartXPos; yield return(new WaitForSeconds(startDelay)); for (float t = 0f; t < 1.0f; t += Time.deltaTime / showSpeedInSeconds) { // opacity animate currentAlpha = Mathf.Lerp(0f, 1f, t); _canvasGroup.alpha = currentAlpha; // position animate currentXPos = Mathf.Lerp(animStartXPos, animEndXPos, t); transform.localPosition = new Vector2(currentXPos, transform.localPosition.y); yield return(null); } // ensure we hit our final value _canvasGroup.alpha = 1; transform.localPosition = new Vector2(animEndXPos, transform.localPosition.y); // only allow button to be clickable if animation has finished _imageUI.raycastTarget = true; // set reveal state, now that we're completed IsRevealed = true; ShowCompleted?.Invoke(); }
public void CompleteReveal() { if (_animationCoroutine != null) { StopCoroutine(_animationCoroutine); } // ensure we hit our final value _canvasGroup.alpha = 1; transform.localPosition = new Vector2(_startXPos, transform.localPosition.y); // only allow button to be clickable if animation has finished _imageUI.raycastTarget = true; IsRevealed = true; ShowCompleted?.Invoke(); }