I am trying to make a small game, where you have to press a specific key in less than a second, or you lose. My idea for it is to generate random letter, start a timer, check if player has done it in time if yes, then repeat, if no then lose the game.
Now to the problem, I have a code for random letter, but when I try to get input for it, Unity says: ArgumentException: Input Key named: K is unknown
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TextCounter : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
char Random_Letter = (char)('A' + Random.Range(0, 26)); // Choose random key
if (Input.GetKeyDown("" + Random_Letter))
{
// Score a point
}
ActiveOnTimer(); // Wait a second
}
private IEnumerator ActiveOnTimer()
{
while (true)
{
yield return new WaitForSeconds(1f);
}
}
}
Here is the code, but I belive the real problem is in
char Random_Letter = (char)('A' + Random.Range(0, 26)); // Choose random key if (Input.GetKeyDown("" + Random_Letter))
Hope someone can help me