我有一个 3D 对象,我想用鼠标/手指滑动来旋转它,所以我制作了下面的脚本。
对象的旋转在编辑器上看起来很流畅,但是在真实设备(android)上玩游戏时,旋转并没有立即跟随手指移动,跟随手指需要几毫秒,它不流畅并且控制变得困难并且令人沮丧!
float sensitivity = 0.8f;
Vector2 firstPressPos;
Vector2 secondPressPos;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
//save began touch 2d point
firstPressPos = new Vector3(Input.mousePosition.x, Input.mousePosition.y);
}
if (Input.GetMouseButton(0))
{
//save ended touch 2d point
secondPressPos = new Vector3(Input.mousePosition.x, Input.mousePosition.y);
if (firstPressPos != secondPressPos)
{
float RotX = Input.GetAxis("Mouse X") * sensitivity * Time.deltaTime;
float RotY = Input.GetAxis("Mouse Y") * sensitivity * Time.deltaTime;
transform.RotateAround(Vector3.up, RotX);
transform.RotateAround(Vector3.right, -RotY);
}
}
}
HUH函数
慕村9548890
相关分类