| | | 1 | | using System.Collections; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using UnityEngine; |
| | | 4 | | |
| | | 5 | | public class Lightable : MonoBehaviour { |
| | 1336 | 6 | | public bool on { get; private set; } |
| | | 7 | | |
| | | 8 | | // Lightable game objects are off by default at start |
| | 2 | 9 | | public void Start() { |
| | 2 | 10 | | on = false; |
| | 2 | 11 | | gameObject.GetComponentInChildren<Light>().enabled = false; |
| | 2 | 12 | | } |
| | | 13 | | |
| | 2 | 14 | | public void ToggleLight() { |
| | | 15 | | // Toggle light switch |
| | 2 | 16 | | on = !on; |
| | 2 | 17 | | gameObject.GetComponentInChildren<Light> ().enabled = |
| | | 18 | | !gameObject.GetComponentInChildren<Light> ().enabled; |
| | | 19 | | // Change message based on light switch position |
| | 3 | 20 | | if (on) { |
| | 1 | 21 | | gameObject.GetComponent<Inspectable>().inspectMessage = "That's much better..."; |
| | 2 | 22 | | } else { |
| | 1 | 23 | | gameObject.GetComponent<Inspectable>().inspectMessage = "Hello darkness, my old friend..."; |
| | 1 | 24 | | } |
| | | 25 | | |
| | | 26 | | |
| | 2 | 27 | | } |
| | | 28 | | } |