Aff*_*hab 5 c# parameter-passing uibutton unity5
我想从检查员点击按钮发送多个参数?
Unity不允许这样做,我怎样才能做到这一点?还有其他方法吗?有几十个按钮,我使用相同的方法为所有按钮,但发送不同的参数,现在我需要发送多种类型的参数.想不通怎么样?
Pro*_*mer 10
从编辑器调用Unity函数有限制.它只能接受一个参数,该函数必须是非static函数.
这就是了解如何从代码订阅事件的重要性.下面Button是单击a时调用的函数示例.它将字符串和整数传递给该函数.很简单,将其拖动Button到编辑器中的某个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();
}
Run Code Online (Sandbox Code Playgroud)