diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 380f46f..03acb0c 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -467,6 +467,7 @@ public void OnClickSubmitSignIn() public void onClickSamePlayers() { + Debug.Log("Play with same players !", this); Room newRoom = myRoom; newRoom.currentState = (int)GameState.Explanation; newRoom.questions.Clear(); @@ -484,11 +485,13 @@ public void onClickSamePlayers() } public void onClickNewPlayers() { - myRoom.currentState = (int)GameState.EnteringName; - myRoom.currentQuestionId = 0; - myRoom.questions = null; - myRoom.players = null; - string json = JsonConvert.SerializeObject(myRoom); + Debug.Log("Play with new players !", this); + Room newRoom = myRoom; + newRoom.currentState = (int)GameState.EnteringName; + newRoom.currentQuestionId = 0; + newRoom.questions = null; + newRoom.players = null; + string json = JsonConvert.SerializeObject(newRoom); myOnlineRoom.SetRawJsonValueAsync(json).ContinueWithOnMainThread(task => { @@ -502,6 +505,9 @@ public void onClickNewPlayers() private void OnCurrentQuestionChanged(object sender, ValueChangedEventArgs onlineValue) { + if (onlineValue == null || onlineValue.Snapshot == null || onlineValue.Snapshot.Value == null) + return; + int questionId = onlineValue.Snapshot.Value.ConvertTo(); Debug.Log($"new question ! Q{(onlineValue.Snapshot.Value.ConvertTo())}"); diff --git a/Assets/Scripts/QuestionHandler.cs b/Assets/Scripts/QuestionHandler.cs index 2aeae02..27bdd7c 100644 --- a/Assets/Scripts/QuestionHandler.cs +++ b/Assets/Scripts/QuestionHandler.cs @@ -12,7 +12,7 @@ public class QuestionHandler : MonoBehaviour public PromptList promptList; private GameManager gameManager; - private List questionsToAnswer; + private List questionsToAnswer = new List(); private int activeAnsweredQuestionIndex = 0; private const int FirstQuestionIndex = 0; @@ -25,21 +25,14 @@ public class QuestionHandler : MonoBehaviour /// void OnEnable() { + activeAnsweredQuestionIndex = FirstQuestionIndex; + submitButton.interactable = true; + submitButton.GetComponent().text = "Submit"; gameManager = managers.GetComponent(); questionsToAnswer = gameManager.myRoom.GetQuestionsByPlayer(gameManager.currentPlayer); Redraw(activeAnsweredQuestionIndex); } - /// - /// Called when the script is disabled. - /// Cleans up resources and resets the activeAnsweredQuestionIndex. - /// - void OnDisable() - { - questionsToAnswer = null; - activeAnsweredQuestionIndex = FirstQuestionIndex; - } - /// /// Redraws the UI with the information from the current question. ///