-
Notifications
You must be signed in to change notification settings - Fork 0
/
TweenPulse.cs
71 lines (64 loc) · 1.98 KB
/
TweenPulse.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// TweenPulse.cs
// Last edited 9:45 PM 04/21/2015 by Aaron Freedman
using UnityEngine;
namespace Assets.PrototypingKit
{
public class TweenPulse : MonoBehaviour
{
public float pulsePeriod;
public float sizeMultiplier;
public float gravity;
private float lastPulse;
private Vector3 originalScale;
public bool flashOnPulse;
public Color flashColor;
public float colorGravity;
private Color originalColor;
public bool autoTween;
private void Start()
{
lastPulse = Time.time;
originalScale = transform.localScale;
originalColor = GetComponent<Renderer>().material.color;
}
private void FixedUpdate()
{
if (autoTween)
{
if (Time.time > lastPulse + pulsePeriod)
{
Pulse();
}
}
if (transform.localScale != originalScale)
{
transform.localScale = Vector3.Lerp(transform.localScale, originalScale, gravity * Time.deltaTime);
}
if (GetComponent<Renderer>().material.color != originalColor)
{
if (flashOnPulse)
{
GetComponent<Renderer>().material.color = Color.Lerp(GetComponent<Renderer>().material.color, originalColor,
colorGravity * Time.deltaTime);
}
}
}
public void Pulse()
{
Pulse(flashColor);
}
public void Pulse(Color color)
{
Pulse(color, sizeMultiplier);
}
public void Pulse(Color color, float scale)
{
lastPulse = Time.time;
transform.localScale *= scale;
if (flashOnPulse)
{
GetComponent<Renderer>().material.color = color;
}
}
}
}