这里采用js脚本方式,Label可以以文本的形式展示出一段字符串信息,在这里特别注意一下中文的显示问题,可以修改js文件的编码方式为UTF-8,这样呢能很好的解决中文乱码问题。
#pragma strict
var str:String;
var imageTexture:Texture;
private var imageWidth:int;
private var imageHeight:int;
private var screenWidth:int;
private var screenHeight:int;
function Start () {
screenWidth=Screen.width;
screenHeight=Screen.height;
imageWidth=imageTexture.width;
imageHeight=imageTexture.height;
}
function OnGUI() {
GUI.Label(Rect(100,10,100,30),str);
GUI.Label(Rect(100,40,100,30),"当前平面宽:"+screenWidth);
GUI.Label(Rect(100,80,100,30),"当前平面高:"+screenHeight);
GUI.Label(Rect(100,120,imageWidth,imageHeight),imageTexture);
}
本文介绍如何在Unity中利用GUI.Label组件显示文本信息,包括解决中文显示问题的方法,并展示了如何通过脚本动态更新显示内容。
7982

被折叠的 条评论
为什么被折叠?



