unity3d 第一天

来源:互联网 发布:组播mac地址有什么用 编辑:程序博客网 时间:2024/03/29 20:20


Script01 (mainCamera对象)

#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,150,100,30),str);GUI.Label(Rect(100,190,100,30),"当前屏幕宽:" + screenWidth);GUI.Label(Rect(100,230,100,30),"当前屏幕高:" + screenHeight);//将体育显示在屏幕中GUI.Label(Rect(100,130,200,150),imageTexture);//GUI.Label(Rect(100,280,imageWidth,imageHeight),imageTexture);}function Update () {}
Script02 (cube对象)
#pragma strict//模型移动速度var TranslateSpeed = 20;//模型旋转速度var RotateSpeed = 1000;//绘制UIfunction OnGUI(){GUI.backgroundColor = Color.red;if(GUI.Button(Rect(10,10,70,30),"向左旋转")){transform.Rotate(Vector3.up *Time.deltaTime * (-RotateSpeed));}if(GUI.Button(Rect(90,10,70,30),"向前移动")){transform.Translate(Vector3.forward * Time.deltaTime * TranslateSpeed);}if(GUI.Button(Rect(170,10,70,30),"向右旋转")){transform.Rotate(Vector3.up *Time.deltaTime * RotateSpeed);}if(GUI.Button(Rect(170,50,70,30),"向右移动")){transform.Translate(Vector3.right * Time.deltaTime * TranslateSpeed);}if(GUI.Button(Rect(90,50,70,30),"向后移动")){transform.Translate(Vector3.forward * Time.deltaTime * (-TranslateSpeed));}if(GUI.Button(Rect(10,50,70,30),"向左移动")){transform.Translate(Vector3.right * Time.deltaTime * (-TranslateSpeed));}GUI.Label(Rect(250,10,200,30),"模型位置" +transform.position);GUI.Label(Rect(250,50,200,30),"模型的旋转" +transform.rotation); }/*function Start () {}function Update () {}*/


0 0
原创粉丝点击