[英]Stop Z rotation of gameObject on touch in Unity
Hi am trying to Rotate the gameobject in X-axis and Y-axis on touch, the code works perfectly, but it effects z-rotation also, I don't want Z-Rotation, My gameObject does not contain Rigid-body so i can't apply Z-rotation constraints. 您好,我尝试在触摸时在X轴和Y轴上旋转游戏对象,代码工作正常,但它也会影响z旋转,我也不想Z旋转,我的gameObject不包含刚体,所以我无法应用Z旋转约束。 I have searched the problem on internet but can't get any appropriate solution.
我已经在互联网上搜索了问题,但找不到任何合适的解决方案。 Any help would be appreciated.
任何帮助,将不胜感激。 Thankx
Thankx
Here is my code: 这是我的代码:
public class Rot : MonoBehaviour {
private float RotateSpeed = 10f;
void OnMouseDrag () {
float xRot = Input.GetAxis ("Mouse X") * RotateSpeed * Mathf.Deg2Rad;
float yRot = Input.GetAxis ("Mouse Y") * RotateSpeed * Mathf.Deg2Rad;
transform.RotateAround (Vector3.up, -xRot);
transform.RotateAround (Vector3.right, yRot);
}
}
Try this, 尝试这个,
transform.Rotate(new Vector3(-xRot,yRot,0.0f),Space.Self);
If you want to set absolute rotation use transform.localEulerAngles
如果要设置绝对旋转,请使用
transform.localEulerAngles
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.