打包时候能转动camera的脚本
来源:互联网 发布:mac 画流程图的软件 编辑:程序博客网 时间:2024/05/19 09:04
需要把以下3个脚本加到camera上面,并且把Rotate那个脚本的target设为某个物体即可,可以显示fps,如下:
一个是cameraSetup脚本
using UnityEngine;using System.Collections;public class CameraSetup : MonoBehaviour { public int ScreenWid = 1280; public int ScreenHei = 800; private int scaleWidth ; private int scaleHeight ; // Use this for initialization void Start () { setDesignContentScale(); } public void setDesignContentScale() {#if UNITY_ANDROID //if(scaleWidth ==0 && scaleHeight ==0) //{ int width = Screen.currentResolution.width; int height = Screen.currentResolution.height; int designWidth = ScreenWid; int designHeight = ScreenHei; float s1 = (float)designWidth / (float)designHeight; float s2 = (float)width / (float)height; if(s1 < s2) { designWidth = (int)Mathf.FloorToInt(designHeight * s2); } else if(s1 > s2) { designHeight = (int)Mathf.FloorToInt(designWidth / s2); } float contentScale = (float)designWidth/(float)width; if(contentScale < 1.0f) { scaleWidth = designWidth; scaleHeight = designHeight; } //} if(scaleWidth >0 && scaleHeight >0) { if(scaleWidth % 2 == 0) { scaleWidth += 1; } else { scaleWidth -= 1; } Screen.SetResolution(scaleWidth,scaleHeight,true); }#endif } void OnApplicationPause(bool paused) { if (paused) { } else { setDesignContentScale(); } } // Update is called once per frame void Update () { }}
另一个转动的
using UnityEngine;using System.Collections;public class RotateAndPinch_2 : MonoBehaviour{ public Transform target; private float minVertical = 0f; private float maxVertical = 85f; private float x = 0.0f; private float y = 0.0f; private float distance = 0.0f; private float newdis = 0; private float olddis = 0; // Use this for initialization void Start() { distance = (transform.position - target.position).magnitude; } // Update is called once per frame void Update() { transform.LookAt(target); float dt = Time.deltaTime; x = transform.eulerAngles.y; y = transform.eulerAngles.x; if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) { if (Input.touchCount == 1) { if (Input.GetTouch(0).phase == TouchPhase.Moved) { float x1 = Input.GetAxis("Mouse X"); float y1 = Input.GetAxis("Mouse Y"); x += x1 * dt * 150; y += -y1 * dt * 150; SetPos(x, y); } } if (Input.touchCount == 2) { if (Input.GetTouch(0).phase == TouchPhase.Moved && Input.GetTouch(1).phase == TouchPhase.Moved) { Vector3 s1 = Input.GetTouch(0).position; Vector3 s2 = Input.GetTouch(1).position; newdis=Vector2.Distance(s1,s2); if(newdis>olddis) { distance-=Time.deltaTime*2f; } if(newdis<olddis) { distance+=Time.deltaTime*2f; }// print("distance = "+distance); SetPos(x,y); olddis=newdis; } } } else { if (Input.GetMouseButton(0)) { float x1 = Input.GetAxis("Mouse X"); float y1 = Input.GetAxis("Mouse Y"); x += x1 * dt * 150f; y += -y1 * dt * 150f; SetPos(x, y); } if (Input.GetAxis("Mouse ScrollWheel") != 0) { distance -= Input.GetAxis("Mouse ScrollWheel"); SetPos(x, y); } } } void SetPos(float x, float y) { y = ClampAngle(y, minVertical, maxVertical); var rotation = Quaternion.Euler(y, x, 0.0f); var position = rotation * new Vector3(0.0f, 0.0f, -distance) + target.position; transform.rotation = rotation; transform.position = position; } static float ClampAngle(float angle, float min, float max) { if (angle < -360) angle += 360; if (angle > 360) angle -= 360; return Mathf.Clamp(angle, min, max); }}
将某个物体拖到该脚本的Target里
下面是一个显示FPS的脚本
using UnityEngine;using System.Collections;public class showFPS : MonoBehaviour { public float updateInterval = 0.5F; private float accum = 0; // FPS accumulated over the interval private int frames = 0; // Frames drawn over the interval private float timeleft; // Left time for current interval private string FPS; void Start() { timeleft = updateInterval; } void OnGUI(){ GUIStyle style = new GUIStyle(); style.normal.textColor = new Color( 1, 1, 1); style.fontSize = 40; GUI.skin.label.alignment = TextAnchor.UpperCenter; GUI.Label(new Rect(0,0,200,60),FPS,style); } void Update() { timeleft -= Time.deltaTime; accum += Time.timeScale/Time.deltaTime; ++frames; // Interval ended - update GUI text and start new interval if( timeleft <= 0.0 ) { float fps = accum/frames; FPS ="FPS:"+ System.String.Format("{0:F2}",fps); timeleft = updateInterval; accum = 0.0F; frames = 0; } }}
阅读全文
0 0
- 打包时候能转动camera的脚本
- Unity 3D笔记——脚本让camera转动起来
- 以前能跑步的时候
- OV5848 Camera AF无功能的问题
- .NET 打包的时候数据库一起打包
- 很有意思的转动
- C# 转动的大风车
- CSS3:转动的齿轮
- 转动的div层
- 转动的饼图
- 转动的地球
- 转动的风扇
- 梦想成真:上厕所的时候也能找工作
- 梦想成真:上厕所的时候也能找工作
- 梦想成真:上厕所的时候也能找工作
- 梦想成真:上厕所的时候也能找工作
- 能爱的时候,一定要敢爱。
- 生病的时候能做什么
- 10、vue.js 之render
- 移动端开发——zepto和jquery mobile的区别
- 使用纯文本方式编写软件设计文档
- spring——xml文件配置
- wifi一键配网smartconfig原理及应用
- 打包时候能转动camera的脚本
- SQL语句入门级(MySQL测试)
- Oracle 误操作删除表的恢复方法
- 四种数据库随机获取10条数据的方法
- Codeforecs 808E Selling Sovenirs 枚举+DP(超大背包)
- Linux内存管理(三)——用户空间管理
- 读-李林峰-分布式服务框架和原理1-7
- Python自学笔记1
- 蓝桥杯java第三届决赛第一题--星期日