void Update() { if (toggled && Input.GetAxisRaw("v") == 0) { // toggle is so you cant hold the stick and cycle the letters by frame toggled = false; cycleEnabled = false; StopCoroutine(timer); } else if (!toggled && Input.GetAxisRaw("V") > 0) { Index++; currentBox.selectedLetter = Letters.GetLetter(Index); letterSent?.Invoke(); toggled = true; timer = StartCoroutine(CycleTimer()); } else if (!toggled && Input.GetAxisRaw("V") < 0) { Index--; currentBox.selectedLetter = Letters.GetLetter(Index); letterSent?.Invoke(); toggled = true; timer = StartCoroutine(CycleTimer(false)); } }
IEnumerator CycleLetters(bool positiveCycle = true) { while (cycleEnabled) { yield return(new WaitForSeconds(WorldData.LetterCycleSpeed)); Index += positiveCycle ? 1 : -1; currentBox.selectedLetter = Letters.GetLetter(Index); letterSent?.Invoke(); } }