Пример #1
0
        IEnumerator FlashLoop(float secondsForOneFlash, float minAlpha, float maxAlpha)
        {
            // half the flash time should be on flash in, the other half for flash out
            float flashInDuration  = secondsForOneFlash / 2;
            float flashOutDuration = secondsForOneFlash / 2;

            // start the flash cycle
            while (true)
            {
                OnCycleStart.Invoke();
                // flash in
                for (float t = 0f; t <= flashInDuration; t += Time.deltaTime)
                {
                    Color newColor = _flashImage.color;
                    newColor.a        = Mathf.Lerp(minAlpha, maxAlpha, t / flashInDuration);
                    _flashImage.color = newColor;
                    yield return(null);
                }
                // flash out
                for (float t = 0f; t <= flashOutDuration; t += Time.deltaTime)
                {
                    Color newColor = _flashImage.color;
                    newColor.a        = Mathf.Lerp(maxAlpha, minAlpha, t / flashOutDuration);
                    _flashImage.color = newColor;
                    yield return(null);
                }

                OnCycleComplete.Invoke();
            }
        }
Пример #2
0
    IEnumerator PulseLoop(float secondsForOnePulse, float minSize, float maxSize)
    {
        // half the pulse time should be for grow, and half for shrink
        float growDuration   = secondsForOnePulse / 2;
        float shrinkDuration = secondsForOnePulse / 2;

        // start the pulse loop
        while (true)
        {
            float currentScaleAdjustment;

            OnCycleStart.Invoke();
            // growth cycle
            for (float t = 0; t <= growDuration; t += Time.deltaTime)
            {
                currentScaleAdjustment = Mathf.Lerp(minSize, maxSize, t / growDuration);
                transform.localScale   = new Vector3
                                             (currentScaleAdjustment, currentScaleAdjustment, currentScaleAdjustment);
                yield return(null);
            }
            // shrink cycle
            for (float t = 0; t <= shrinkDuration; t += Time.deltaTime)
            {
                currentScaleAdjustment = Mathf.Lerp(maxSize, minSize, t / shrinkDuration);
                transform.localScale   = new Vector3
                                             (currentScaleAdjustment, currentScaleAdjustment, currentScaleAdjustment);
                yield return(null);
            }

            OnCycleComplete.Invoke();
        }
    }