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 Update () {
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操作的基本示例代码,展示了如何在屏幕上显示文本和图片,并根据屏幕尺寸调整其位置。此示例涉及GUI的基础用法,包括获取屏幕尺寸、纹理尺寸及如何在Update函数中更新GUI元素。

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



