1 using UnityEngine;
2 using
System.Collections;
3
4 [RequireComponent (
typeof (Detonator))]
5 [AddComponentMenu(
"Detonator/Light")]
6 public
class DetonatorLight : DetonatorComponent {
7     
8     
private float _baseIntensity = 1f;
9     
private Color _baseColor = Color.white;
10     
private float _scaledDuration = 0f;
11     
private float _explodeTime = -1000f;
12     
13     
private GameObject _light;
14     
private Light _lightComponent;
15     
public float intensity;
16     
17     
override public void Init()
18     {
19         _light =
new GameObject ("Light");
20         _light.transform.parent =
this.transform;
21         _light.transform.localPosition = localPosition;
22         _lightComponent = (Light)_light.AddComponent <Light>();
23         _lightComponent.type = LightType.Point;
24         _lightComponent.enabled =
false;
25     }
26     
27     
private float _reduceAmount = 0f;
28     
void Update ()
29     {
30         
31         
if ((_explodeTime + _scaledDuration > Time.time) && _lightComponent.intensity > 0f)
32         {
33             _reduceAmount = intensity * (Time.deltaTime/_scaledDuration);
34             _lightComponent.intensity -= _reduceAmount;
35         }
36         
else
37         {
38             
if (_lightComponent)
39             {
40                 _lightComponent.enabled =
false;
41             }
42         }
43         
44     }
45     
46     
override public void Explode()
47     {
48         
if (detailThreshold > detail) return;
49         
50         _lightComponent.color = color;
51         _lightComponent.range = size *
50f;
52         _scaledDuration = (duration * timeScale);
53         _lightComponent.enabled =
true;
54         _lightComponent.intensity = intensity;
55         _explodeTime = Time.time;
56     }
57     
58     
public void Reset()
59     {
60         color = _baseColor;
61         intensity = _baseIntensity;
62     }
63 }