您的位置:首页 > 其它

如何控制屏幕(摄像机)移动

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);//当鼠标在下侧时,使相机向下移动
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  屏幕