Reset Button Fixed(Again)In my attempt to get Pause to work today, I discovered in issue with the Reset Button I should have noticed the first time.
I was using a checkedOff variable in my TodosHandler script to pass a variable to the BoardManager script, that manages the game board. The TodoScript attached to the TodoButton sets the checkedOff variable in the TodosHandler to true. Update() in BoardManager waits for the checkedOff variable in TodosHandler to be true, and then it sets the "clicked" variable in BoardManager to true. This signals a while loop to stop, which then loads the next tile in BoardManager.
Originally, I thought this wasn't working when the game was paused because Update() wasn't running when time.TimeScale was set to 0. This, however was false, but I didn't know that at the time. To fix this, I gave the TodoScript direct access to the "clicked" variable in the BoardManager script, and let it set "clicked" directly. This was changing the variable to true, but it did not trigger the while loop to stop.
The reason for this, I eventually discovered, was that I had multiple instances of BoardManager. I discovered this by using:
Debug.Log("Parent of this BoardManager is " + transform.parent.gameObject);
Debug.Log("Root parent of this BoardManager is " + transform.root.gameObject);
I'm not entirely sure why my previous fix for the ResetButton worked. I'm guessing that the change I made allowed the ResetButton script to find only one copy of the BoardManager instance instead of two, or maybe it found the correct instance instead of the wrong one.
So I removed the copy of BoardManager from the ResetButton and changed the ResetButton code to:
BoardManager.boardManager.ResetBoard();In order to access the variable directly from TodoScript, I had previously added to my list of variables:
public static BoardManager boardManager = null;and then also added, to the "void Awake();" function:
boardManager = this;This allowed me to access the ResetBoard() function directly as well.
However, after implementing this code, I came to discover that tiles are still not loaded when the game is paused. Apparently Update() is still called while Time.timeScale is 0, but
while (!clicked)never completes, because time has stopped.
yield return new WaitForSeconds(0.01f);
Since setting Time.timeScale to 0 doesn't work with WaitForSeconds, I instead decided to pause the player by making a "paused" variable in the Player script. I made that variable accessible by other scripts so that those scripts can pause the player.
The player moves through:
horizontal = (int)Input.GetAxisRaw("Horizontal");and some other scripts in Update() of the Player script, so I added "if (!paused)" before that.
vertical = (int)Input.GetAxisRaw("Vertical");
I then added code to the Pause button script to set Player.player.pause to true or false and I added an "Event Trigger" component to the Todo field. I then added a Select and Deselect even to the event trigger, added a PausePlayer and UnpausePlayer function to the Pause script, and assigned those to Select and Deselect so that the player is paused when the field is selected and unpaused when the field is deselected. This keeps the player movement from being effected when typing in todo names and keeps todos from being typed in when the player is moving.
I also added a black image, with an alpha, with the word "Paused" overlayed on top of the game as a visual queue.
I also added a gameActive variable to the boardManager so that the pause scripts can check to see if the game is Active. The game is by default, paused when the level is loading, so this prevents the scripts from trying to unpause the game when the level is still loading.
Currently music doesn't pause with the game, but it can be paused separately by clicking the music button. I did this intentionally to give players more control over whether the music is, or is not playing. The music does start by default when the level is finished loading.
Window Scaling Fixed(sort of)
I (sort of) fixed scaling. I set the aspect ratio to 16:9 and then set the windows to stretch vertically, with their anchors set to the bound of the panel. This makes the panels scale correctly. However, the aspect ratio is stuck at 16:9
Previously, all todos you did while the game was active would not be counted. I changed this, so that there is now a counter in BoardManager that keeps track of those unused todos. There is also a panel that tell you how many unused todos you have, and a button you can click that will use those unused todo points as if they were a todo you were clicking on the left panel. I could give more technical information, but this post is already a bit long.
I may add some kind of confirmation popup for the Reset Game button that asks whether you are sure you want to reset the game, and maybe some hover over tooltips if that's possible, but that's the only thing I can think of right now.
I'll take a little time to think about whether there is anything else I want to add before release. I'll also do some testing and make some builds. Then I will release a working build for everyone to download.