Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using UnityEngine;
using UnityEngine.UI;
public class ImageHintAnimation : MonoBehaviour
{
public Image imageToChange;
private Color imageToChangeDefaultColor;
public Color animationStartColor;
public Color animationEndColor;
public 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;
}
// Update is called once per frame
void Update()
{
if (animating)
{
this.timer += Time.deltaTime;
Animate();
}
}
public void AnimationTrigger()
{
if (imageToChange != null)
animating = true;
}
private void Animate()
{
if (timer >= animateDuration)
{
animating = false;
timer = 0;
imageToChange.color = imageToChangeDefaultColor;
}
else
{
imageToChange.color = Color.Lerp(animationStartColor, animationEndColor, Mathf.PingPong(Time.time, 1));
}
}
}