我想用VS 2019在Unity中做一个语音识别,我遇到了一个有字符串和动作的字典,像这样。
private Dictionary<string, Action[]> actions = new Dictionary<string, Action[]>();
我使用了一个动作列表,因为我想做得更复杂,而不是识别简单的单词。比如说 向右转 或 变绿.
但是,当我想在这个字典中添加一个元素时。
actions.Add("up", Up); // first line in example
其中Up是一个函数,它给我的错误是 "Argument 2: cannot convert from 'method group' to 'Action[]'"(在我注释的第一行)。
private void Up()
{
posY += speed;
}
在Up下,它给了我一个错误 "Argument 2: cannot convert from 'method group' to 'Action[]'"(在我在例子中注释的第一行)。但是如果我的字典不是Action[]而是Action(不是数组),它就能正常工作。
首先,我怎样才能解决这个问题,摆脱这个错误?其次,对于高级语音识别,有没有更好的方法?我想识别一个短语,如 向右转,变色为绿色.
字典中存放着一个Action的数组。
actions.Add("up", new Action[] { Up });