unity里,我定义了一个char类型,生成了随机26个字母,然后想用键盘事件,按下这些随机字母,则摧毁主体,但是Input。GetKeyDown()括号里不能直接写char,会报错:cannot convert from 'char' to 'UnityEngine.KeyCode'。应该怎么转换呢?2D的打字游戏。
public class people : MonoBehaviour
{
GameObject peopleGam;
public Text peopleText;
char a;
void Start()
{
peopleGam = this.gameObject;
char ch=(char)('A'+Mathf.RoundToInt(Random.Range(0,26))); //产生随机数 转换为char类型
peopleText.text = ch.ToString();
if (Input.GetKeyDown(a))
{
Destroy(peopleGam);
}
}