简体   繁体   English

NITY按钮单击事件是否在UNITY3D中发布?

[英]NGUI Button Click Event Issue in UNITY3D?

I need to try to get button name whenever clicks on button.I did a sample but doesn't work with arg value but it works successfully without arg value.I am new to UNITY3D.So please see the below code and suggest me what to do? 每当单击按钮时,我都需要尝试获取按钮名称。我做了一个示例,但不能使用arg值,但是可以成功使用而没有arg值。我是UNITY3D的新手,所以请看下面的代码并建议我如何做?

Code : 代码:

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);
    }
}

Error is : 错误是:

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)

The error message means that the signature for the method Unity/NGUI is trying to invoke has no parameters. 错误消息表示Unity / NGUI尝试调用的方法的签名没有参数。

How did you tell NGUI to call that method on button click? 您如何告诉NGUI在单击按钮时调用该方法?

It's been a long while since I've used NGUI, but it seems like the way to get a capture a click event is to have a script on the button that has a method OnClick(). 自从我使用NGUI以来已经有很长时间了,但是似乎捕获点击事件的方法是在按钮上放一个脚本,该脚本具有方法OnClick()。 By nature of the script being on that button you have access to the button that was clicked (this.gameObject.name). 根据该按钮上脚本的性质,您可以访问被单击的按钮(this.gameObject.name)。 Also, according to these docs you can use UICamera.currentTouchID to get the id of the button that was clicked. 另外,根据这些文档,您可以使用UICamera.currentTouchID来获取单击的按钮的ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM