unity3d - 为什么我的函数没有出现在 Unity 的 On Click 字段中?
问题描述
我为按钮编写了一个简单的脚本,并把它扔到了按钮的“On Click”中,但是我的Button1函数并没有显示在那里。如何解决这个问题呢?
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public class Nikita : MonoBehaviour
{
public void Button1()
{
Debug.Log("button clicked");
}
// Start is called before the first frame update
void Start()
{
Debug.Log("started");
}
// Update is called once per frame
void Update()
{
}
}
解决方案
我会尝试实现IPointerClickHandler
按照文档中的建议,“场景中存在事件系统以允许点击检测”。你可以检查这个例子。
对于您的情况,可能类似于(未调试):
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
public class Nikita : MonoBehaviour, IPointerClickHandler
{
public void OnPointerClick(PointerEventData eventData)
{
Debug.Log("button clicked");
}
// Start is called before the first frame update
void Start()
{
Debug.Log("started");
}
// Update is called once per frame
void Update()
{
}
}
推荐阅读
- php - 上传的文件超过了 php.ini 中的 upload_max_filesize 指令但文件小于限制
- ios - PHAssetResource.assetResources 使用有效的 PHAsset 返回零结果
- php - 如何使用 php 重置 Html 表单的值?
- android-view - 这个drawable有什么问题?
- php - 在提交表单后但在重定向和退出之前回显成功消息
- javascript - 将带有 JSON 数据的 POST 请求从 HTML 发送到 Java Rest Web 服务时出现 HTTP 错误 415
- c++ - 从具有不同列的文本文件读取到数组 C++
- c# - 在另一个项目中读取 JSON 文件时出现问题
- html - 如何在范围输入滑块旁边居中文本的垂直对齐
- django - django.urls.exceptions.NoReverseMatch:找不到带有参数“(1、5)”的“教授”的反向