我开发了一个基本游戏,其中可以使用 WASD 键在地图上移动相机,我想调整基本按钮操作以在触摸屏上工作,但我不确定如何开始。
这是我目前用于移动相机的 c# 代码
if (Input.anyKey && allowInput)
{
moved = false;
if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W)) { moved = true; Translate(Vector3.forward * Time.deltaTime * speed); }
if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S)) { moved = true; Translate(Vector3.back * Time.deltaTime * speed);}
if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) { moved = true; Translate(Vector3.left * Time.deltaTime * speed);}
if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)) { moved = true; Translate(Vector3.right * Time.deltaTime * speed); }
if (OnCamManuallyMoved != null && moved)
{
Vector3 pos = tr.position;
if (pos.x < min_xz.x) pos.x = min_xz.x;
if (pos.x > max_xz.x) pos.x = max_xz.x;
if (pos.z < min_xz.y) pos.z = min_xz.y;
if (pos.z > max_xz.y) pos.z = max_xz.y;
tr.position = pos;
OnCamManuallyMoved(); // call callback
}
}