摄像机跟着鼠标左右移动而移动,上下移动而前进后退

private float cameraMoveSpeed = 1.5f;
void Update()
{
moveThisCamera();
}
void moveThisCamera()
{
if (Input.mousePosition.x <= 10)
{
float xNew = this.transform.position.x;
xNew -= cameraMoveSpeed * Time.deltaTime;
this.transform.position = new Vector3(xNew, this.transform.position.y, this.transform.position.z);
}
if (Input.mousePosition.x >= (Screen.width - 10))
{
float xNew = this.transform.position.x;
xNew += cameraMoveSpeed * Time.deltaTime;
this.transform.position = new Vector3(xNew, this.transform.position.y, this.transform.position.z);
}

if (Input.mousePosition.y <= 10)
{
float zNew = this.transform.position.z;
zNew -= cameraMoveSpeed * Time.deltaTime;
this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y, zNew);
}
if (Input.mousePosition.y >= (Screen.height - 10))
{
float zNew = this.transform.position.z;
zNew += cameraMoveSpeed * Time.deltaTime;
this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y, zNew);
}
}

posted @   U3DEngineer  阅读(278)  评论(0编辑  收藏  举报
努力加载评论中...
< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示