[Unity]界面GUI程序常用的脚本类

本文详细介绍了在Unity引擎中进行界面GUI程序开发时,常用的脚本类及其应用,提供了一个全面的脚本类索引链接,帮助开发者快速理解和使用。
摘要由CSDN通过智能技术生成

脚本总索引:http://game.ceeger.com/Script/index.Classes.html

1 按钮生成
function OnGUI () {
	
	if (GUI.Button (Rect (10,10,150,100), "I am a button")) {
		
		print ("You clicked the button!");

	}
}



2 按钮场景载入

/* Example level loader */

function OnGUI () {

	// Make a background box

	GUI.Box (Rect (10,10,100,90), "Loader Menu");

	// Make the first button. If it is pressed, Application.Loadlevel (1) will be executed

	if (GUI.Button (Rect (20,40,80,20), "Level 1")) {

		Application.LoadLevel (1);

	}

	// Make the second button.

	if (GUI.Button (Rect (20,70,80,20), "Level 2")) {

		Application.LoadLevel (2);

	}

}



3 按钮点击生效时间
/* Flashing button example */

function OnGUI () {

	if (Time.time % 2 < 1) {

		if (GUI.Button (Rect (10,10,200,20), "Meet the flashing button")) {

			print ("You clicked me!");

		}

	}

}




4 创建按钮背景BOX
/* Screen.width & Screen.height example */

function OnGUI () {

	GUI.Box (Rect (0,0,100,50), "Top-left");                             
	//Rect 生成2D矩形的函数,用于摄像机,画面,GUI

	GUI.Box (Rect (Screen.width - 100,0,100,50), "Top-right");

	GUI.Box (Rect (0,Screen.height - 50,100,50), "Bottom-right");

	GUI.Box (Rect (Screen.width - 100,Screen.height - 50,100,50), "Bottom-left");

}


5 在按钮上显示文字
/* String Content example */

function OnGUI () {

	GUI.Label (Rect (0,0,100,50), "This is the text string for a Label Control");     
	//显示文字

}



6 显示图像,声明一个公共变量的Texture2D,并通过这样的内容作为参数变量的名称
/* Texture2D Content example */

var controlTexture : Texture2D;      //controlTexture为图像的名称

function OnGUI () {

	GUI.Label (Rect (0,0,100,50), controlTexture);

}




7 显示图像的例子

                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值