国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Unity3D學習筆記第一課

2019-11-17 02:17:41
字體:
來源:轉載
供稿:網友

Unity3D學習筆記第一課

第一課程:1.Unity類名必須與文件名保持一致2.講屬性設置為public可以在Unity中訪問 public float speed;// Use this for initializationvoid Start () {}// Update is called once per framevoid Update () {//獲取左右方向鍵的的值(范圍為-1到1)float amtToMove = Input.GetAxis ("Horizontal") * speed;//使用矩陣進行平移gameObject.transform.Translate (Vector3.right * amtToMove);}

3.攝像機:游戲的輸出畫面是由攝像機所觀測的場景而實現的,將游戲場景呈現到2D的計算機屏幕,有兩種投影方式為透視投影和正交投影,Unity默認為透視投影,透視投影感覺有距離感,正交投影沒有距離感。開發Unity2D游戲,需要將投影方式改為正交投影。

透視投影的三個主要參數:FieldofView(視角),NearClipPlane(近看平面),FarClipPlane(遠看平面)4.GameObject對象包含transform,camera屬性,GetComponet和AddComponent等方法5.Transform實現對象的位置、旋轉以及縮放 position rotation localScale Translate方法 Rotate方法6.Input.GetAxis()與Input.GetAxisRaw()檢測方向鍵 檢測上下移動Input.GetAxis("Vertical") 檢測左右移動Input.GetAxis("Horizontal")7.Time類 deltaTime 上一幀到本幀的時間,單位為秒8.三個Update的調用順序MonoBehaviour.FixedUpdate()MonoBehaviour.Update()MonoBehaviour.LateUpdate()

9.循環移動方塊

public class Player : MonoBehaviour {

public float playerSpeed;// Use this for initializationvoid Start () {}// Update is called once per framevoid Update () {Debug.Log ("Update");var moveto = Input.GetAxis ("Horizontal") *Time.deltaTime* playerSpeed;gameObject.transform.Translate (Vector3.right * moveto);

if (transform.position.x > 9.15) {transform.position=new Vector3(-9.15f,transform.position.y);}

if (transform.position.x <- 9.15) {transform.position=new Vector3(9.15f,transform.position.y);}}

void LateUpdate(){Debug.Log ("LateUpdate");}

void FixedUpdate(){Debug.Log("FixedUpdate");}}9.創建按鈕并響應按鈕操作

void OnGUI(){if (GUI.Button (new Rect (0, 0, 100, 50), "Play")) {

} else if (GUI.Button (new Rect (0, 60, 100, 50), "Pause")) {} else if (GUI.Button (new Rect (0, 120, 100, 50), "Stop")) {}}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新昌县| 沙坪坝区| 都昌县| 印江| 宽甸| 吴川市| 石楼县| 那曲县| 宣化县| 大冶市| 汾阳市| 巴林右旗| 张北县| 东港市| 安福县| 黎川县| 前郭尔| 金溪县| 天全县| 阜南县| 寻甸| 城市| 襄城县| 重庆市| 迭部县| 天气| 石阡县| 嘉祥县| 白山市| 桐庐县| 嘉荫县| 灯塔市| 德江县| 长治市| 南投市| 桓台县| 开化县| 天等县| 泰顺县| 蕉岭县| 岑溪市|