| | | 1 | | using UnityEngine; |
| | | 2 | | using System.Collections; |
| | | 3 | | |
| | | 4 | | public class DigitalClock : MonoBehaviour { |
| | | 5 | | public DigitalClockValue hoursDCV; |
| | | 6 | | public DigitalClockValue minutesDCV; |
| | | 7 | | public DigitalClockValue secondsDCV; |
| | | 8 | | public DigitalClockValue pointsDCV; |
| | 2 | 9 | | public bool pointFlicker = true; |
| | | 10 | | public float clockSpeed; |
| | 5 | 11 | | public int score { get; set; } |
| | | 12 | | |
| | 1 | 13 | | void Start() { |
| | 1 | 14 | | StartCoroutine ("PlayTime"); |
| | 2 | 15 | | if (pointFlicker && secondsDCV == null) StartCoroutine ("PlayPointFlicker"); |
| | 1 | 16 | | } |
| | | 17 | | |
| | 1 | 18 | | public void SetReverseClock(bool setReverse){ |
| | 1 | 19 | | if (hoursDCV != null) |
| | 1 | 20 | | hoursDCV.reverse = setReverse; |
| | 1 | 21 | | if (minutesDCV != null) |
| | 1 | 22 | | minutesDCV.reverse = setReverse; |
| | 1 | 23 | | if (secondsDCV != null) |
| | 0 | 24 | | secondsDCV.reverse = setReverse; |
| | 1 | 25 | | } |
| | | 26 | | |
| | 1 | 27 | | IEnumerator PlayTime(){ |
| | 4 | 28 | | while (true) { |
| | 2 | 29 | | if (secondsDCV!=null){ |
| | 0 | 30 | | yield return new WaitForSeconds (1.0f /clockSpeed); |
| | 0 | 31 | | secondsDCV.ChangeTimeValue(); |
| | 0 | 32 | | if (pointFlicker) { |
| | 0 | 33 | | pointsDCV.ChangeTimeValue (); |
| | 0 | 34 | | int hours = hoursDCV.currentValue, |
| | 0 | 35 | | minutes = minutesDCV.currentValue; |
| | 0 | 36 | | GameObject.FindGameObjectWithTag("clock").GetComponent<Inspectable> ().inspectMessage = |
| | | 37 | | string.Format ("It reads {0:D2}:{1:D2}.", hours, minutes); |
| | 0 | 38 | | score = (hours * 60) + minutes; |
| | 0 | 39 | | } |
| | 0 | 40 | | } |
| | 2 | 41 | | else { |
| | 2 | 42 | | yield return new WaitForSeconds (60.0f/clockSpeed); |
| | 1 | 43 | | minutesDCV.ChangeTimeValue (); |
| | 1 | 44 | | int hours = hoursDCV.currentValue, |
| | 1 | 45 | | minutes = minutesDCV.currentValue; |
| | 1 | 46 | | GameObject.FindGameObjectWithTag ("clock").GetComponent<Inspectable> ().inspectMessage = |
| | | 47 | | string.Format ("It reads {0:D2}:{1:D2}.", hours, minutes); |
| | 1 | 48 | | score = (hours * 60) + minutes; |
| | 1 | 49 | | } |
| | 1 | 50 | | } |
| | | 51 | | } |
| | 1 | 52 | | IEnumerator PlayPointFlicker(){ |
| | 228 | 53 | | while (pointFlicker) { |
| | 114 | 54 | | yield return new WaitForSeconds (1.0f /clockSpeed); |
| | 113 | 55 | | pointsDCV.ChangeTimeValue (); |
| | 113 | 56 | | } |
| | 0 | 57 | | } |
| | | 58 | | } |