| | | 1 | | using System.Collections; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using UnityEngine; |
| | | 4 | | using UnityEngine.Serialization; |
| | | 5 | | |
| | | 6 | | public class Hourglass : MonoBehaviour |
| | | 7 | | { |
| | | 8 | | [FormerlySerializedAs("hourglassTop")] |
| | | 9 | | public GameObject HourglassTop; |
| | | 10 | | [FormerlySerializedAs("hourglassBottom")] |
| | | 11 | | public GameObject HourglassBottom; |
| | | 12 | | [FormerlySerializedAs("timerFill")] |
| | 22 | 13 | | public float TimerFill = 1.0f; |
| | | 14 | | [FormerlySerializedAs("particleSand")] |
| | | 15 | | public ParticleSystem ParticleSand; |
| | | 16 | | |
| | | 17 | | Material m_TopMat; |
| | | 18 | | Material m_BotMat; |
| | | 19 | | |
| | | 20 | | // Start is called before the first frame update |
| | | 21 | | void Start() |
| | 11 | 22 | | { |
| | 11 | 23 | | m_TopMat = HourglassTop.GetComponent<MeshRenderer>().material; |
| | 11 | 24 | | m_BotMat = HourglassBottom.GetComponent<MeshRenderer>().material; |
| | 11 | 25 | | } |
| | | 26 | | |
| | | 27 | | // Update is called once per frame |
| | | 28 | | void Update() |
| | 13006 | 29 | | { |
| | 13006 | 30 | | if (Vector3.Dot(transform.up, Vector3.down) > 0.8 && TimerFill > 0) |
| | 0 | 31 | | { |
| | 0 | 32 | | TimerFill -= 0.1f * Time.deltaTime; |
| | 0 | 33 | | ParticleSand.Play(); |
| | 0 | 34 | | } |
| | 13006 | 35 | | else if (Vector3.Dot(transform.up, Vector3.down) < -0.8 && TimerFill < 1) |
| | 0 | 36 | | { |
| | 0 | 37 | | TimerFill += 0.1f * Time.deltaTime; |
| | 0 | 38 | | ParticleSand.Play(); |
| | 0 | 39 | | } else |
| | 13006 | 40 | | { |
| | 13006 | 41 | | ParticleSand.Stop(); |
| | 13006 | 42 | | } |
| | | 43 | | |
| | 13006 | 44 | | m_TopMat.SetFloat("TimerFill", TimerFill); |
| | 13006 | 45 | | m_BotMat.SetFloat("TimerFill", TimerFill); |
| | 13006 | 46 | | } |
| | | 47 | | } |