| | | 1 | | using System.Collections; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using UnityEngine; |
| | | 4 | | |
| | | 5 | | public class MovePillow : MonoBehaviour { |
| | 2 | 6 | | public Lightable[] lamps = new Lightable[2]; |
| | | 7 | | public GameObject key; // Hack to hide key |
| | 2 | 8 | | bool isMoved = false; |
| | | 9 | | |
| | 1 | 10 | | void Start() { |
| | 1 | 11 | | GetComponent<Inspectable>().enabled = false; |
| | 1 | 12 | | GetComponent<Collectable>().enabled = false; |
| | 1 | 13 | | GetComponent<Collider>().enabled = false; |
| | 1 | 14 | | key.GetComponent<Collider>().enabled = false; |
| | 1 | 15 | | } |
| | | 16 | | |
| | 2441 | 17 | | void Update() { |
| | 2441 | 18 | | if (!isMoved && (lamps[0].on || lamps[1].on)) { |
| | 0 | 19 | | SetInteractable (true); |
| | 2441 | 20 | | } else { |
| | 2441 | 21 | | SetInteractable (false); |
| | 2441 | 22 | | } |
| | 2441 | 23 | | } |
| | | 24 | | |
| | 2441 | 25 | | public void SetInteractable(bool status) { |
| | 2441 | 26 | | GetComponent<Inspectable>().enabled = status; |
| | 2441 | 27 | | GetComponent<Collectable>().enabled = status; |
| | 2441 | 28 | | GetComponent<Collider>().enabled = status; |
| | 2441 | 29 | | } |
| | | 30 | | |
| | 1 | 31 | | void SetKey(bool status) { |
| | 2 | 32 | | if (key != null) { |
| | 1 | 33 | | key.GetComponent<Collider> ().enabled = status; |
| | 1 | 34 | | } |
| | 1 | 35 | | } |
| | | 36 | | |
| | | 37 | | // Move pillow aside to reveal the hidden key |
| | 1 | 38 | | public void MovePillowAway() { |
| | 1 | 39 | | transform.Translate(0.5f, 0, 0); |
| | 1 | 40 | | isMoved = true; |
| | 1 | 41 | | SetKey (true); |
| | 1 | 42 | | } |
| | | 43 | | } |