日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國(guó)內(nèi)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁(yè) > php開源 > 綜合技術(shù) > Unity 2D游戲相機(jī)控制(水平,豎直,角色居中三種模式)

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

來(lái)源:程序員人生   發(fā)布時(shí)間:2015-05-19 08:00:21 閱讀次數(shù):5337次
做2D游戲的時(shí)候,不過有3種模式,1種是只有豎直向上,1種是只有水平方向,1種是有水平又有豎直方向,我最近做游戲多關(guān)卡模式,不同模式就有著不1樣的相機(jī)控制,依照平時(shí)的寫法,或許有很多人就1下子寫了3個(gè)相機(jī)腳本,現(xiàn)在我用了1個(gè)枚舉類型來(lái)控制3個(gè)不1樣的相機(jī),貼代碼:
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; // 相機(jī)移動(dòng)速度,初始速度清零 private Vector3 velocity = Vector3.zero; // 相機(jī)單例 private static CameraCtrl instance; public static CameraCtrl Instance { get { return instance; } } // 屏幕的默許寬高的1/100 (預(yù)編譯) #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(); } } // 設(shè)置相機(jī) 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:// 豎直相機(jī) transform.position = Vector3.SmoothDamp (transform.position, new Vector3 (transform.position.x, destination.y, destination.z), ref velocity, dampTime); break; case CameraType.Horizontal:// 水平相機(jī) transform.position = Vector3.SmoothDamp (transform.position, new Vector3 (destination.x, transform.position.y, destination.z), ref velocity, dampTime); break; case CameraType.Normal:// 無(wú)窮制的相機(jī) transform.position = Vector3.SmoothDamp (transform.position, destination, ref velocity, dampTime); break; default: break; } } // 設(shè)置目標(biāo) void SetTarget () { target = GameObject.FindGameObjectWithTag ("Player").transform; } }

生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 色婷婷综合色 | 九九九久久国产免费 | 国产高清在线 | 天天拍天天操 | 国产精品一区二区三区在线免费观看 | 久久精品国产亚洲一区二区三区 | 免费视频一区二区 | 欧美日韩高清在线观看 | 一级片黄色 | 精品国产欧美日韩 | 亚洲色图在线观看 | 成人激情视频在线观看 | 国产5页 | 欧美日韩国产在线看 | 国产亚洲精品久 | 欧美日韩不卡在线 | 国产精品爽爽久久久久久 | 国产人成看黄久久久久久久久 | 欧美精品在线一区二区 | 99精品国产在热久久婷婷 | 天堂电影在线观看 | 黄色3级视频 | 在线二区 | 在线国产视频观看 | 国产一级精品视频 | 91大神新作在线观看 | 中文字幕成人av | 精品成人av一区二区在线播放 | 视频一区亚洲 | 亚洲免费一区二区 | 91 中文字幕 | 亚洲综合一区在线 | 中文字幕一区二区三区日韩精品 | 韩国三级大全久久网站 | 亚洲成人av观看 | 久久久精品电影 | 国产精品一区二区久久 | 日韩欧美区 | 久久免费视频网 | 久久久久一区二区三区 | 亚洲精品动漫久久久久 |