在Unity3D中,我想在world Space中绘制一个图形用户界面。需要的是UI不是静态的。它必须从脚本中创建。
但我想不出该怎么做。调用GUI: box ()只是将框添加到屏幕UI。
编辑:
我做了一些研究,发现GUI元素使用的是画布渲染器和脚本。
添加画布渲染器不是问题
GameObject o = new GameObject(child.OriginalName);
o.AddComponent<CanvasRenderer>();但是我不能添加脚本。
我还尝试使用GUIText组件。
o.AddComponent<GUIText>();
o.transform.position = new Vector3(0, 0, 0);
o.AddComponent<CanvasRenderer>();
o.GetComponent<GUIText>().text = child.InnerHtml;
o.GetComponent<GUIText>().font = Font.CreateDynamicFontFromOSFont("Arial", 5);
o.GetComponent<GUIText>().fontSize = 5;但这完全没有显示任何内容
发布于 2016-09-22 15:39:35
好了,我把这个弄好了,这里不需要船长。
包括以下内容
using UnityEngine.UI;然后你就可以访问UI组件了。例如,文本
o.AddComponent<CanvasRenderer>();
o.AddComponent<Text>();
o.GetComponent<Text>().text = "Text"
o.GetComponent<Text>().font = Font.CreateDynamicFontFromOSFont("Arial", 7);
o.GetComponent<Text>().fontSize = 7;
o.GetComponent<Text>().alignment = TextAnchor.MiddleRight;其中o是一个游戏对象。
只需将画布设置为GameObject的父级,它就可以正常工作
https://stackoverflow.com/questions/39572870
复制相似问题