Skip to content
Snippets Groups Projects
ImageHintAnimation.cs 1.2 KiB
Newer Older
  • Learn to ignore specific revisions
  • using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    John Schihada's avatar
    John Schihada committed
    using UnityEngine.UI;
    
    John Schihada's avatar
    John Schihada committed
    
    public class ImageHintAnimation : MonoBehaviour
    {
        public Image imageToChange;
    
        [System.NonSerialized]
        public Color imageToChangeDefaultColor;
        private IEnumerator routine;
    
    John Schihada's avatar
    John Schihada committed
    
        // Start is called before the first frame update
    
    John Schihada's avatar
    John Schihada committed
        {
            if (imageToChange != null)
                imageToChangeDefaultColor = imageToChange.color;
        }
    
        public void AnimationTrigger()
        {
    
            routine = Animation();
            StartCoroutine(routine);
    
            IEnumerator Animation()
    
                for ( var track = 0f.LerpInTime(0, 0, GlobalBehaviour.hintAnimationDuration)
                    ; track.MoveNext();)
    
                    yield return imageToChange.color =
                        Color.Lerp
                        ( GlobalBehaviour.hintAnimationStartColor
                        , GlobalBehaviour.hintAnimationEndColor
                        , Mathf.PingPong(Time.time, 1));
    
                imageToChange.color = imageToChangeDefaultColor;
            }
    
        public void ResetAnimation()
    
            if (routine != null)
                StopCoroutine(routine);