如何控制屏幕(摄像机)移动
2017-09-08 14:43
218 查看
using UnityEngine; using System.Collections; public class ScrenSlip : MonoBehaviour { // Use this for initialization void Start() { } // Update is called once per frame void Update() { Vector3 v1 = Camera.main.ScreenToViewportPoint(Input.mousePosition);//将摄像机屏幕坐标转换为 if (v1.x >0.9f) { transform.Translate(Vector3.left* Time.deltaTime * 3, Space.World);//当鼠标在右侧时,使相机向右移动(这里是left是因为转换之后摄像机是反的属于正常) } if (v1.x <0.1f) { transform.Translate(Vector3.right * Time.deltaTime * 3, Space.World);//当鼠标在左侧时,使相机向左移动 } if (v1.y >0.9f) { transform.Translate(Vector3.back * Time.deltaTime * 3, Space.World);//当鼠标在上侧时,使相机向上移动 } if (v1.y <0.1f) { transform.Translate(Vector3.forward * Time.deltaTime * 3, Space.World);//当鼠标在下侧时,使相机向下移动 } } }
相关文章推荐
- unity中如何用鼠标右键控制摄像机视角上下左右移动
- unity 如何控制摄像机跟随角色移动
- Unity3D-ScrollView中使用Layout布局后用代码如何控制ScrollView移动到指定位置
- Unity 3d 如何实现点击屏幕,npc自动移动到点击位置
- 如何用代码控制以不同屏幕方向打开新页面【iOS】
- Android控制图片在屏幕内缩放和移动
- 如何在activity中控制屏幕点亮与关闭
- IOS&Android通用屏幕控制(移动旋转缩放)
- 鼠标控制摄像机旋转,平移,物体的移动
- 在unity3d开发2d游戏控制摄像机移动以及主角移动的方法
- 如何移动组件的位置,例如如何将UIAlertView显示在屏幕上部
- Unity 2D战棋类 摄像机的局部移动控制
- IOS&Android通用屏幕控制(移动旋转缩放)
- 直接控制OSG摄像机移动
- android如何在activity中控制屏幕点亮与关闭
- UI界面基础如何用鼠标控制物体移动
- Unity 通过点击屏幕控制人物移动
- 如何处理移动应用请求的安全性控制
- 如何在activity中控制屏幕点亮与关闭
- 如何移动组件的位置,例如如何将UIAlertView显示在屏幕上部