void Update() { if (state == State.Loading) { if (RhymeScorer.main.GetIsReady()) { state = State.Moving; levelSpawner.Spawn(); player.transform.position = levelSpawner.GetPlayerStart(); inventoryDisplay.gameObject.SetActive(true); } } else if (state == State.Moving) { UpdateHealth(); UpdateInventory(); if (Input.GetKeyDown(KeyCode.Return)) { EnterTypingMode(); } } else if (state == State.Typing) { UpdateHealth(); UpdateInventory(); foreach (char c in Input.inputString) { // Backspace - Remove the last character if (c == '\b') { if (rawAttack.Length > 0) { // refund inventory[rawAttack[rawAttack.Length - 1]]++; rawAttack = rawAttack.Substring(0, rawAttack.Length - 1); } } else if ((c >= "a"[0] && c <= "z"[0]) || (c >= "A"[0] && c <= "Z"[0]) || c == " "[0]) { char lc = System.Char.ToLower(c); if (IsLimitedLetter(lc)) { if (inventory[lc] > 0) { rawAttack += lc; inventory[lc]--; } else { Debug.Log("out of letter " + c); } } else { rawAttack += lc; } } } if (Input.GetKeyDown(KeyCode.Return)) { ExitTypingMode(RhymeScorer.main.IsValidAnswer(rawAttack)); } else if (Input.GetKeyDown(KeyCode.Escape)) { ExitTypingMode(false); } else { typeModeText.text = "[" + rawAttack + "]"; if (rawAttack.Length == 0) { typeModeText.color = Color.white; typeModeText.text = "type!"; typeModeFeedback.text = ""; typeModeFeedback.color = Color.white; } else if (RhymeScorer.main.IsValidAnswer(rawAttack)) { // gather enemies within radius // highlight them if their word rhymes with this one HashSet <Attackable> targets = player.GetVisibility().GetActiveTargets(); bool canAttackAny = false; foreach (Attackable target in targets) { if (target == null) { continue; } if (CanAttackTarget(target)) { canAttackAny = true; target.OnIsInDanger(); ShowLine(target); } else { target.OnIsNotInDanger(); } } if (canAttackAny) { typeModeText.color = Color.red; typeModeFeedback.text = "enter to attack!"; typeModeFeedback.color = Color.red; } else { typeModeText.color = Color.white; typeModeFeedback.text = "no rhyming targets"; typeModeFeedback.color = Color.white; } } else { typeModeText.color = Color.white; typeModeFeedback.text = "not a word"; typeModeFeedback.color = Color.white; } } } }