-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathUIPulse.cs
39 lines (31 loc) · 807 Bytes
/
UIPulse.cs
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
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class UIPulse : MonoBehaviour {
public Gradient colorPattern; // Pattern for the colors to rotate through.
public float pulseSpeed = 1.0f; // How fast to rotate through the colors.
Color baseColor;
MaskableGraphic image;
bool fwd;
float pct;
// Use this for initialization
void Start () {
image = gameObject.GetComponent<MaskableGraphic> ();
image.color = colorPattern.Evaluate (0.0f);
pct = 0.0f;
fwd = true;
}
// Update is called once per frame
void Update () {
if (fwd) {
pct += pulseSpeed * Time.deltaTime;
} else {
pct -= pulseSpeed * Time.deltaTime;
}
if (pct < 0.0f || pct > 1.0f) {
fwd = !fwd;
pct = Mathf.Clamp01 (pct);
}
image.color = colorPattern.Evaluate (pct);
}
}