试图发送一个UnityAction作为一个参数为我的方法之一,比如:传递参数与UnityAction
public void PopulateConversationList(string [] fullConversation, string onLastPagePrompt, string npcName, int stage, UnityAction action)
{
conversations.Add(new Conversation(fullConversation, onLastPagePrompt, npcName, stage, action));
}
dialogHolder.PopulateConversationList(stage1, "Okay", _name, 1, QuestManager.Instance().ActivateQuest);
能正常工作,但现在我想下面的行动作为参数传递:
public void ActivateQuest(int questId)
{
Debug.Log("This is the id: " + questId);
}
然而,当我使用的是有一个参数的操作将无法正常工作:
dialogHolder.PopulateConversationList(stage1, "Okay", _name, 1, QuestManager.Instance().ActivateQuest(2));
以上给予s错误:Cannot convert from void to UnityAction
。 如何将参数传递给UnityAction作为参数?
我叫Action
在谈话中是这样的:
dialog.OnAccept(ConvList[i].onLastPagePrompt,() =>
{
ConvList[i].action();
dialog.Hide();
});
编辑:我最终的解决方案与打算:
enter dialogHolder.PopulateConversationList(stage1, "Okay", _name, 1,() =>
{
QuestManager.Instance().ActivateQuest(0);
});
这样我可以调用多种方法为好。
你甚至懒得显示'testMethod'函数以及'MyAction'是如何声明的。这些是必需的,以帮助你。 – Programmer
@Programmer对不起,我试图让它更具可读性,我猜想让它变得更糟。我编辑了问: – Majs