From 0f405ca483177909b81b99c54928f8c355579c3c Mon Sep 17 00:00:00 2001 From: Pedro Arthur Date: Thu, 2 May 2019 14:30:23 -0300 Subject: [PATCH] Fix play/pause button when reloading --- Assets/GameController.cs | 9 ++++++++- Assets/PlayController.cs | 21 +++++++++------------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Assets/GameController.cs b/Assets/GameController.cs index 4d2aced..cbffab8 100644 --- a/Assets/GameController.cs +++ b/Assets/GameController.cs @@ -22,7 +22,7 @@ public class GameController : MonoBehaviour Node current; System.Random rng = new System.Random(); - + bool is_playing = false; static GameController instance; @@ -61,6 +61,7 @@ void Start() return ret; }); + is_playing = true; } // Update is called once per frame @@ -181,11 +182,13 @@ public void SetBPM(int bpm) public void Play() { scheduler.StartTick(); + is_playing = true; } public void Pause() { scheduler.StopTick(); + is_playing = false; } public void Reload() @@ -194,6 +197,10 @@ public void Reload() current = CreateNode(new Vector3(-2, 2, 0)).GetComponent(); Start(); } + public bool IsPlaying() + { + return is_playing; + } } diff --git a/Assets/PlayController.cs b/Assets/PlayController.cs index 2a0e386..e26ce73 100644 --- a/Assets/PlayController.cs +++ b/Assets/PlayController.cs @@ -4,7 +4,6 @@ public class PlayController : MonoBehaviour { - bool toggle = false; GameObject bar; GameObject arrow; private void Awake() @@ -21,24 +20,22 @@ void Start() // Update is called once per frame void Update() { - - } - - public void Click() - { - if (toggle) + if (GameController.GetInstance().IsPlaying()) { - GameController.GetInstance().Play(); bar.SetActive(true); arrow.SetActive(false); - } - else + } else { - GameController.GetInstance().Pause(); bar.SetActive(false); arrow.SetActive(true); } + } - toggle = !toggle; + public void Click() + { + if (GameController.GetInstance().IsPlaying()) + GameController.GetInstance().Pause(); + else + GameController.GetInstance().Play(); } }