Repository navigation
Expand file tree
/
Copy pathLightAdjuster.cs
More file actions
70 lines (60 loc) · 1.93 KB
/
Copy pathLightAdjuster.cs
File metadata and controls
70 lines (60 loc) · 1.93 KB
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LightAdjuster : MonoBehaviour {
public Light myLight;
// Range Variables
public bool changeRange = false;
public float rangeSpeed = 1.0f;
public float maxRange = 10.0f;
public bool repeatRange = false;
// Intensity Variables
public bool changeIntensity = false;
public float intensitySpeed = 1.0f;
public float maxIntensity = 10.0f;
public bool repeatIntensity = false;
// Color variables
public bool changeColors = false;
public float colorSpeed = 1.0f;
public Color startColor;
public Color endColor;
public bool repeatColor = false;
float startTime;
// Use this for initialization
void Start () {
myLight = GetComponent<Light>();
startTime = Time.time;
}
// Update is called once per frame
void Update () {
if(changeRange) {
if(repeatRange) {
myLight.range = Mathf.PingPong(Time.time * rangeSpeed, maxRange);
} else {
myLight.range = Time.time * rangeSpeed;
if(myLight.range >= maxRange) {
changeRange = false;
}
}
}
if(changeIntensity) {
if(repeatIntensity) {
myLight.intensity = Mathf.PingPong(Time.time * intensitySpeed, maxIntensity);
} else {
myLight.intensity = Time.time * intensitySpeed;
if(myLight.intensity >= maxIntensity) {
changeIntensity = false;
}
}
}
if(changeColors) {
if(repeatColor) {
float t = (Mathf.Sin(Time.time - startTime * colorSpeed));
myLight.color = Color.Lerp(startColor, endColor, t);
} else {
float t = Time.time - startTime * colorSpeed;
myLight.color = Color.Lerp(startColor, endColor, t);
}
}
}
}