首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NGUI在UNITY3D中单击事件问题?

NGUI在UNITY3D中单击事件问题?
EN

Stack Overflow用户
提问于 2014-05-22 18:05:31
回答 1查看 4K关注 0票数 1

每当点击按钮时,我都需要尝试获取按钮名。我做了一个示例,但是没有arg值就不能工作,但是没有arg值,它可以成功地工作。我是UNITY3D.So新手,请看下面的代码,并建议我怎么做?

代码:

代码语言:javascript
复制
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);
    }
}

错误是:

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-22 21:15:15

错误消息意味着Unity试图调用的方法的签名没有参数。

你是如何让NGUI在点击按钮时调用该方法的?

自从我使用NGUI以来已经有很长时间了,但是获得单击事件捕获的方法似乎是在按钮上有一个带有OnClick()方法的脚本。根据脚本在该按钮上的性质,您可以访问单击的按钮(this.gameObject.name)。此外,根据这些文档,您可以使用UICamera.currentTouchID获取单击按钮的id。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23814195

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档