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
using UnityEngine;
public class MeshRendererHintAnimation : MonoBehaviour
{
public MeshRenderer meshRendererToChange;
private Color meshRendererToChangeDefaultColor;
//Make sure when using RGBA-Colors, the A-value of animationStartColor
//and animationEndColor is the same OR try with value = 255
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 (meshRendererToChange != null)
meshRendererToChangeDefaultColor = meshRendererToChange.material.color;
}
// Update is called once per frame
void Update()
{
if (animating) {
this.timer += Time.deltaTime;
Animate();
}
}
public void AnimationTrigger() {
if (meshRendererToChange != null)
animating = true;
}
private void Animate() {
if (timer >= animateDuration)
{
animating = false;
timer = 0;
meshRendererToChange.material.color = meshRendererToChangeDefaultColor;
}
else {
meshRendererToChange.material.color = Color.Lerp(animationStartColor, animationEndColor, Mathf.PingPong(Time.time, 1));
}
}
}