我需要在点击按钮时尝试获取按钮名称。我做了一个示例,但没有使用arg值,但它没有arg值成功。我是UNITY3D的新手。所以请看下面的代码并建议我该怎么做?
代码:
using UnityEngine;
using System.Collections;
public class IG : MonoBehaviour
{
// Use this for initialization
void Start ()
{
Debug.Log (" **** Start() **** ");
}
// Update is called once per frame
void Update ()
{
}
//TODO :: Button Click event
public void IGBtn(string BtnName)
{
Debug.Log (" **** IGBtn Clicked **** "+BtnName);
}
}
错误是:
MissingMethodException: The best match for method IGBtn has some invalid parameter.
System.MonoType.InvokeMember (System.String name, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object target, System.Object[] args, System.Reflection.ParameterModifier[] modifiers, System.Globalization.CultureInfo culture, System.String[] namedParameters) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System/MonoType.cs:520)
UnityEngine.SetupCoroutine.InvokeMember (System.Object behaviour, System.String name, System.Object variable) (at C:/BuildAgent/work/d3d49558e4d408f4/Runtime/Export/Coroutines.cs:19)
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
UIButtonMessage:Send() (at Assets/NGUI/Scripts/Interaction/UIButtonMessage.cs:77)
UIButtonMessage:OnClick() (at Assets/NGUI/Scripts/Interaction/UIButtonMessage.cs:56)
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
UICamera:Notify(GameObject, String, Object) (at Assets/NGUI/Scripts/UI/UICamera.cs:680)
UICamera:ProcessTouch(Boolean, Boolean) (at Assets/NGUI/Scripts/UI/UICamera.cs:1194)
UICamera:ProcessMouse() (at Assets/NGUI/Scripts/UI/UICamera.cs:948)
UICamera:Update() (at Assets/NGUI/Scripts/UI/UICamera.cs:803)
答案 0 :(得分:0)
错误消息表示Unity / NGUI尝试调用的方法的签名没有参数。
你是如何告诉NGUI在点击按钮时调用该方法的?
自从我使用NGUI以来已经有很长一段时间了,但似乎获取点击事件的方法是在按钮上有一个脚本OnClick()。根据该按钮上的脚本的性质,您可以访问被单击的按钮(this.gameObject.name)。此外,根据这些docs,您可以使用UICamera.currentTouchID来获取所单击按钮的ID。