我想在检查员点击按钮时发送多个参数?
Unity 不允许这样做,我该如何实现?还有其他办法吗? 有几十个按钮,我对所有按钮使用相同的方法但发送不同的参数,现在我需要发送多种类型的参数。不知道怎么办?
最佳答案
从编辑器调用 Unity 功能有限制。它只能接受一个参数,并且该函数必须是非static
函数。
这就是了解如何从代码订阅事件的重要性的原因。以下是单击 Button
时调用的函数示例。它向该函数传递一个字符串和一个整数。很简单,将 Button
拖到编辑器中的 some Button 槽中,这应该可以工作。
public Button someButton;
void OnEnable()
{
//Register Button Events
someButton.onClick.AddListener(() => buttonCallBack("Hello Affan", 88));
}
private void buttonCallBack(string myStringValue, int myIntValue)
{
Debug.Log("Button Clicked. Received string: " + myStringValue + " with int: " + myIntValue);
}
void OnDisable()
{
//Un-Register Button Events
someButton.onClick.RemoveAllListeners();
}
关于c# - 统一 5 : How to pass multiple parameters on button click function from inspector?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38518903/