简体   繁体   English

Unity:将按钮脚本添加到3D gameObject

[英]Unity: Add Button Script to 3D gameObject

I'm trying to add the Unity Button Script to a 3d gameObject. 我正在尝试将Unity Button脚本添加到3d gameObject。 When I tried this by adding it onto a cube, I can't get the desired behaviours. 当我尝试将其添加到多维数据集时,无法获得所需的行为。 How can I get the 3d object to work like a button? 如何使3d对象像按钮一样工作? In particular the highlighting colors, the click events. 特别是突出显示的颜色,单击事件。 I was speculating that perhaps it uses the wrong raycaster, and if the raycaster specificaiton is changed some how it would work? 我推测它可能使用了错误的射线广播仪,并且如果改变射线广播仪的规格,它将如何工作? Does anyone have a good enough understanding of the source code to explain if this is possible, and if so what I would need to do to achieve this? 是否有人对源代码有足够的了解,以解释这是否可能,如果可以,我将需要做什么? Thanks. 谢谢。

Rik 里克

You could do it by using OnMouseDown() function. 您可以使用OnMouseDown()函数来实现。 Here is the link Unity Docs 这是Unity Docs的链接

您还需要将图像脚本和按钮脚本一起添加。

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

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