| 1 | using System.Collections; |
| 2 | using System.Collections.Generic; |
| 3 | using UnityEngine; |
| 4 | |
| 5 | public class BlinkyLight : MonoBehaviour |
| 6 | { |
| 7 | private Tween blinkTween = new Tween(Easing.EaseInOutCubic); |
| 8 | [SerializeField] private Renderer lightModelRenderer; |
| 9 | [SerializeField] private Light light; |
| 10 | private bool on = false; |
| 11 | |
| 12 | // Start is called before the first frame update |
| 13 | void Start() |
| 14 | { |
| 15 | blinkTween.onChange = t => |
| 16 | { |
| 17 | light.range = t * 10; |
| 18 | lightModelRenderer.material.color = Color.Lerp(Color.black, Color.red, t); |
| 19 | light.intensity = t * 10; |
| 20 | }; |
| 21 | } |
| 22 | |
| 23 | // Update is called once per frame |
| 24 | void Update() |
| 25 | { |
| 26 | if(!blinkTween.active) |
| 27 | { |
| 28 | if(on) |
| 29 | { |
| 30 | on = false; |
| 31 | blinkTween.Start(1, 0, 0.8f); |
| 32 | } |
| 33 | else |
| 34 | { |
| 35 | on = true; |
| 36 | blinkTween.Start(0, 1, 0.8f); |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | } |