多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > 綜合技術 > Unity 2D游戲相機控制(水平,豎直,角色居中三種模式)

Unity 2D游戲相機控制(水平,豎直,角色居中三種模式)

來源:程序員人生   發布時間:2015-05-19 08:00:21 閱讀次數:5327次
做2D游戲的時候,不過有3種模式,1種是只有豎直向上,1種是只有水平方向,1種是有水平又有豎直方向,我最近做游戲多關卡模式,不同模式就有著不1樣的相機控制,依照平時的寫法,或許有很多人就1下子寫了3個相機腳本,現在我用了1個枚舉類型來控制3個不1樣的相機,貼代碼:
using UnityEngine; using System.Collections; public class CameraCtrl : MonoBehaviour { public enum CameraType { Vertical, Horizontal, Normal } public CameraType cameraType; public float dampTime = 1.5f; public Transform target; // 相機移動速度,初始速度清零 private Vector3 velocity = Vector3.zero; // 相機單例 private static CameraCtrl instance; public static CameraCtrl Instance { get { return instance; } } // 屏幕的默許寬高的1/100 (預編譯) #if UNITY_ANDROID private static float devHeight = 8.54f; private static float devWidth = 4.8f; #elif UNITY_IPHONE private static float devHeight = 9.6f; private static float devWidth = 6.4f; #else private static float devHeight = 19.20f; private static float devWidth = 10.80f; #endif // Use this for initialization void Awake () { instance = this; // 屏幕適配 float screenHeight = Screen.height; //Debug.Log ("screenHeight = " + screenHeight); //this.GetComponent<Camera>().orthographicSize = screenHeight / 200.0f; float orthographicSize = this.GetComponent<Camera>().orthographicSize; float aspectRatio = Screen.width * 1.0f / Screen.height; float cameraWidth = orthographicSize * 2 * aspectRatio; //Debug.Log ("cameraWidth = " + cameraWidth); if (cameraWidth < devWidth) { orthographicSize = devWidth / (2 * aspectRatio); Debug.Log ("new orthographicSize = " + orthographicSize); this.GetComponent<Camera>().orthographicSize = orthographicSize; } } // Update is called once per frame void LateUpdate () { if (target) { SetCamera(); } else { SetTarget(); } } // 設置相機 void SetCamera () { Vector3 point = GetComponent<Camera> ().WorldToViewportPoint (target.position); Vector3 delta = target.position - GetComponent<Camera> ().ViewportToWorldPoint (new Vector3 (0.5f, 0.5f, point.z)); Vector3 destination = transform.position + delta; switch (cameraType) { case CameraType.Vertical:// 豎直相機 transform.position = Vector3.SmoothDamp (transform.position, new Vector3 (transform.position.x, destination.y, destination.z), ref velocity, dampTime); break; case CameraType.Horizontal:// 水平相機 transform.position = Vector3.SmoothDamp (transform.position, new Vector3 (destination.x, transform.position.y, destination.z), ref velocity, dampTime); break; case CameraType.Normal:// 無窮制的相機 transform.position = Vector3.SmoothDamp (transform.position, destination, ref velocity, dampTime); break; default: break; } } // 設置目標 void SetTarget () { target = GameObject.FindGameObjectWithTag ("Player").transform; } }

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 少妇下面好紧好多水真爽播放 | 亚洲欧美日韩专区 | 日本护士xxxxx极品 | 在线看日本a毛片 | 嗯啊在线观看免费影院 | 性生活视频网站 | 国内自拍视频在线看免费观看 | 久夜色精品国产一区二区三区 | 中文字幕一区二区三区精彩视频 | 欧美xxxx三人交性视频 | 秋霞午夜伦午夜高清福利片 | 久久精品国产99久久无毒不卡 | 特级黄色淫片 | 亚洲高清在线观看 | 午夜dj视频在线观看免费 | 欧美性大战久久久久久久蜜桃 | 在线亚洲自拍 | 岛国在线123456 | 亚洲第一毛片 | 国产精品久久久久无毒 | 亚洲精品中文字幕乱码三区一二 | 欧美日韩高清在线观看 | 波多野结衣国产精品 | 日韩18| 九色中文 | 欧美成人h版 | 国产一精品一aⅴ一免费 | 看日本黄色大片 | free性vido另类重口 | 伦伦影院精品一区 | 国产亚洲人成网站在线观看 | 视色在线视频 | 日本高清免费网站zzzzzzzz | 亚洲三级久久 | 99日韩 | 一区二区三区四区在线观看视频 | 亚洲一区二区三区四区在线 | 自拍偷拍校园春色 | 激情久久免费视频 | 国产精品毛片在线更新 | 久久久欧美综合久久久久 |