//Function for the clear all button. clears letters and sets the amount of slots to the initial one if there were extra. public void ClearAll() { FMODUnity.RuntimeManager.PlayOneShot("event:/SFX/clearAll"); for (int i = 0; i < slotsParent.childCount; i++) { if (slotsParent.GetChild(i).childCount > 1) { GameObject letter = slotsParent.GetChild(i).transform.GetChild(1).gameObject; LetterDragHandler handler = letter.GetComponent <LetterDragHandler>(); if (CheckIfVowel(letter)) { handler.Remove(true); } else { handler.Remove(false); } } } if (slotsParent.childCount > amountOfSlots) { for (int i = slotsParent.childCount; i-- > amountOfSlots;) { GameObject slot = slotsList.Last().gameObject; Destroy(slot); slotsList.Remove(slot); } } GreyOutLetters(0, false); x = 0; }
//Method used to animate the letters moving from stacks to slots. //PRONE TO CHANGE!! public IEnumerator LetterLerp(Vector2 startPos, Vector2 endPos, GameObject letter, int siblingIndex, bool consonant) { float timer = letterMoveSpeed; while (timer <= 1f) { timer += Time.deltaTime; float vals = Mathf.Lerp(0, 1, timer); letter.transform.localScale = new Vector2(vals, vals); yield return(new WaitForEndOfFrame()); } if (consonant) { LetterDragHandler handler = letter.GetComponent <LetterDragHandler>(); GameObject dummy = GameObject.Find(handler.id.ToString()); Debug.Log(dummy.name); letter.transform.SetParent(handler.originalParent); //layoutGroupH.spacing += 0.0001f; letter.transform.SetSiblingIndex(dummy.transform.GetSiblingIndex()); //letter.transform.localScale = new Vector2(1, 1); Destroy(dummy); //Debug.Log(siblingIndex); } }
//Function for the backspace public void RemoveLetter() { if (amountOfSlots != AvailableSlots()) { FMODUnity.RuntimeManager.PlayOneShot("event:/SFX/backspace"); if (LetterToDisable() != null) { GameObject letter = LetterToDisable(); LetterDragHandler handler = letter.GetComponent <LetterDragHandler>(); if (CheckIfVowel(letter)) { handler.Remove(true); } else { handler.Remove(false); } if (slotsParent.childCount > amountOfSlots) { GameObject lastItem = slotsList.Last().gameObject; Destroy(lastItem); slotsList.Remove(lastItem); } } } if (AvailableSlots() == amountOfSlots - 1) { GreyOutLetters(0, false); x = 0; } Debug.Log("X: " + x); Debug.Log("LastIndex" + lastIndex); }