您的位置:首页 > 移动开发 > Unity3D

unity限制目标物旋转角度

2016-03-22 14:45 429 查看
根据项目需要,做一个灭火器喷火的效果,鼠标改装成了一个灭火器,在灭火器旋转的时候,场景里的灭火器也跟着旋转但是限制灭火器的旋转角度。
public Transform rotateTarget;      //  限制旋转对象
float moveSpeed = 10;
float minAngleY = 80;
float maxAngleY = 110;
float minAngleX= -20;
float maxAngleX =20;
float rotationY = 0;
float rotationX = 0;
void Update()
{

if (null == rotateTarget)
return;
rotationX +=  Input.GetAxis("Mouse X") * moveSpeed;
rotationX = Mathf.Clamp(rotationX, minAngleX, maxAngleX);
rotationY += Input.GetAxis("Mouse Y") * moveSpeed;
rotationY = Mathf.Clamp(rotationY, minAngleY, maxAngleY);
rotateTarget.localEulerAngles = new Vector3(-rotationY, rotationX, rotateTarget.rotation.z);

}





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