Skip to content
Snippets Groups Projects
Select Git revision
  • 3a63ea1f4cc3bacaa7a5a2c5574197e4202df47e
  • master default
  • JS-based-scroll-rendering
  • Paul_Marius_Level
  • Paul_Marius_2
  • Paul_Marius
  • Andi_Mark
  • be-UnityWebView
  • gitignoreFrameitServer
  • ZimmerBSc
  • Bugfix_StageLoading
  • stages
  • MAZIFAU_Experimental
  • tsc/coneworld
  • tsc/fact-interaction
  • marcel
  • MaZiFAU_TopSort
  • mergeHelper
  • zwischenSpeichern
  • tempAndrToMaster
  • SebBranch
  • 3.0
  • v2.1
  • v2.0
  • v1.0
25 results

ImageHintAnimation.cs

Blame
  • MaZiFAU's avatar
    Marco Zimmer authored
    +Added Scenes: MainMenue, LoadingScreen +Stage: Save-Load fuctionality +Sorted Prefabs and Scripts Folder
    f818ac70
    History
    ImageHintAnimation.cs 1.71 KiB
    using UnityEngine;
    using UnityEngine.UI;
    using static GlobalBehaviour;
    
    public class ImageHintAnimation : MonoBehaviour
    {
        public Image imageToChange;
        public Color imageToChangeDefaultColor { get; set; }
    
        private Color animationStartColor;
        private Color animationEndColor;
    
        private float animateDuration;
        private bool animating = false;
        private float timer = 0;
    
        // Start is called before the first frame update
        void Start()
        {
            if (imageToChange != null)
                imageToChangeDefaultColor = imageToChange.color;
    
            updateAnimationParameters();
        }
    
        // Update is called once per frame
        void Update()
        {
            if (animating)
            {
                this.timer += Time.deltaTime;
                Animate();
            }
        }
    
        public void AnimationTrigger()
        {
            if (imageToChange != null)
            {
                updateAnimationParameters();
                animating = true;
            }
        }
    
        public void ResetAnimation()
        {
            if (imageToChange != null)
            {
                Reset();
            }
        }
    
        private void Animate()
        {
            if (timer >= animateDuration)
            {
                Reset();
            }
            else
            {
                imageToChange.color = Color.Lerp(animationStartColor, animationEndColor, Mathf.PingPong(Time.time, 1));
            }
    
        }
    
        private void Reset()
        {
            animating = false;
            timer = 0;
            imageToChange.color = imageToChangeDefaultColor;
        }
    
        private void updateAnimationParameters()
        {
            animationStartColor = GlobalBehaviour.hintAnimationStartColor;
            animationEndColor = GlobalBehaviour.hintAnimationEndColor;
            animateDuration = GlobalBehaviour.hintAnimationDuration;
        }
    }