-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorLerper.cs
More file actions
31 lines (27 loc) · 791 Bytes
/
Copy pathColorLerper.cs
File metadata and controls
31 lines (27 loc) · 791 Bytes
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ColorLerper : MonoBehaviour {
public float speed = 1.0f;
public Color startColor;
public Color endColor;
public bool repeatable = false;
float startTime;
// Use this for initialization
void Start () {
startTime = Time.time;
}
// Update is called once per frame
void Update () {
if (!repeatable)
{
float t = (Time.time - startTime) * speed;
GetComponent<Renderer>().material.color = Color.Lerp(startColor, endColor, t);
}
else
{
float t = (Mathf.Sin(Time.time - startTime) * speed);
GetComponent<Renderer>().material.color = Color.Lerp(startColor, endColor, t);
}
}
}