该功能不会出现在OnClick() Unity按钮UI中。

huangapple go评论52阅读模式
英文:

The function does not apear in the OnClick() unity button UI

问题

以下是您的代码的中文翻译:

这是我的代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Example : MonoBehaviour
{
    public void ButtonClickHandler()
    {
        Debug.Log("按钮点击!");
    }
}

Unity中,我的“OnClick”不起作用。

即使我将示例脚本添加到“none”对象部分,我的函数也不会出现:

请注意,图像部分没有翻译。

英文:

Here is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Example : MonoBehaviour
{
    public void ButtonClickHandler()
    {
        Debug.Log("Button Clicked!");
    }
}

My Onclick doesn't work in Unity.

Even when I added my example script to the none object part my functions don't appear:

该功能不会出现在OnClick() Unity按钮UI中。

该功能不会出现在OnClick() Unity按钮UI中。

答案1

得分: 3

你是否将脚本直接从项目中拖到按钮字段中?你想先将示例脚本附加到一个游戏对象,然后将该游戏对象拖放到OnClick字段中。然后,在下拉菜单中会有更多选项,你可以在示例/ButtonClickHandler () 下找到你的函数。

英文:

Did you drag a script directly from the project into the field in the button?

You want to attach your Example script to a GameObject first, and then drag and drop that game object into the OnClick field. Then you'll get more options in the dropdown, and you can find your function there under Example/ButtonClickHandler ()

huangapple
  • 本文由 发表于 2023年7月6日 18:00:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76627654.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定