将文本附加到游戏对象 [英] Attach text to a gameobject

查看:41
本文介绍了将文本附加到游戏对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有两种方法可以做到.但它们都不适合我.

I know there are 2 ways to do it. But none of them works for me.

我尝试的第一种方法是创建一个游戏对象,然后在其中放置一个立方体(形状)和一个带有文本的画布.我将形状、画布(世界空间)和文本的位置设置为 (0,0,0),以便它们保持在一起.然而,只有立方体出现了.并且禁用立方体仍然不会使文本显示.

The first way I tried is to create a gameObject and then put a cube(shape) and a canvas with Text in it. I set the position of shape, canvas(world space) and text to (0,0,0) so that they will stay together. However, Only the cube showed up. And disabling the cube still doesn't make the text display.

所以我删除了它并将文本网格添加到形状中,这需要我删除网格过滤器.而现在我能看到的只是一片空白.我有什么设置错误吗?

So I removed it and added Text Mesh to the shape and this required me to remove Mesh Filter. And now what I can see is only an empty space. Do I have any settings wrong?

推荐答案

您可以使用 UI Button 游戏对象和 3D 立方体来做到这一点.步骤如下:

You can do that with a UI Button game object and a 3D cube. The steps are as follows:

  1. 在您的空场景中,创建一个 3D 立方体.

  1. In your empty scene, create a 3D Cube.

之后,创建一个 UI Button 对象.

After that, create a UI Button object.

现在你有了按钮和画布,拖动画布成为立方体的子元素,像这样:

Now that you have the button and the Canvas, drag the Canvas to become a child of the cube, like this:

现在您必须将 Canvas 设置为 World Space 渲染模式,移除 Canvas Scaler 组件,并设置 Width = Height = 1 和所有 Pos = 0.

Now you have to set the Canvas to World Space render mode, remove the Canvas Scaler component, and set Width = Height = 1 and all Pos = 0.

最后一步,设置按钮:设置Width = Height = 100,所有Scale = 0.01Pos Z = -0.501>.

Final step, setup the Button: set Width = Height = 100, all Scale = 0.01 and Pos Z = -0.501.

现在您拥有一个功能完美的按钮,无论立方体位于何处或旋转何处,它都将保持附着在立方体的正面.

Now you have a perfectly functional button that will stay attached to the front face of the cube, no matter where the cube is positioned or rotated.

您当然可以添加任意数量的按钮,并将它们放置到立方体的不同面(甚至一个面有多个按钮等).

You can of course add as many buttons you want, and position them to different faces of the cube (even more than one button to a single face etc.).

这篇关于将文本附加到游戏对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆