// Executes based on the "KeyboardPressed" event from KeyPressHandler public void OnKeyPressed(string key) { // Start the new point in time startTime = Time.time; this.key = key; // Reference to the key pressed //firstHasBeenPlayed = true; Debug.Log("Slots child is: " + slots.GetChild(helper.currentSlotIndex).name.ToString().ToLower()); Debug.Log("Current index is: " + helper.currentSlotIndex); // If the keyboard is enabled and the slot at the current index is empty if (helper.IsKeyboardEnabled() && helper.IsSolvingIndexEmpty(helper.currentSlotIndex)) { // If the letter to solve at the current slot index matches the letter typed if (slots.GetChild(helper.currentSlotIndex).name.ToString().ToLower() == key.ToString().ToLower()) { isAnimationLooping = false; // Create a copy of the letter, place it in the slot, and increase the slot index. Then call HasChanged() to update the string GameObject l = GameObject.Instantiate((GameObject)Resources.Load(("Letter Prefabs/Letter_" + key.ToString().ToUpper()))); l.transform.SetParent(slots.GetChild(helper.currentSlotIndex), false); l.gameObject.GetComponent <Animation>().Play(); if (helper.keyboard.letterName == true) { helper.PlayKeyboardAudio(helper.currentSlotIndex); } // Remove the drag handler component Destroy(l.GetComponent <DragHandler>()); // Increase the slot index, set the current number of errors to 0, and call HasChanged() if (helper.currentSlotIndex < slots.childCount - 1) { helper.currentSlotIndex++; helper.numErrors = 0; Debug.Log("Starting DisplayLetterHint...1"); //StartCoroutine(DisplayLetterHint()); } else // The word has been solved { helper.ResetProvidedScales(); helper.currentSlotIndex = 0; helper.gameComplete = true; firstHasBeenPlayed = false; StartCoroutine(helper.GameOver()); } HasChanged(); helper.HighlightStartingSlotLetter(helper.currentSlotIndex); } // The letter pressed is incorrect else { if (helper.IsKeyboardEnabled()) { // Increase the number of errors helper.numErrors++; helper.totalErrors++; // Display Letter in slot GameObject l = GameObject.Instantiate((GameObject)Resources.Load(("Letter Prefabs/Letter_" + key.ToString().ToUpper()))); l.transform.SetParent(slots.GetChild(helper.currentSlotIndex), false); // Remove the drag handler component Destroy(l.GetComponent <DragHandler>()); // Adapt the difficulty StartCoroutine(AdaptDifficulty(helper.numErrors, l)); } } } }