指定最终角度进行旋转,方式一:
transform.eulerAngles = new Vector3(x,y,z)
transform.localEulerAngles = new Vector3(x,y,z)
给物体赋予一个新的旋转角度值,Vector3 是最終角度,区别是 localEulerAngles 是相对于 parent transform's rotation
官方文档有一句提醒 Only use this variable to read and set the angles to absolute values. Don't increment them, as it will fail when the angle exceeds 360 degrees. Use Transform.Rotate instead.
指定最终角度进行旋转,方式二:
transform.rotation = Quaternion.Euler(new Vector3(x,y,z))
transform.localRotation = Quaternion.Euler(new Vector3(x,y,z))
两个方法接受一个四元数 Quaternion,需要通过方法 Quaternion.Euler 将 Vector3 转换成四元数,同 eulerAngles 一样,接收的是最终旋转角度值
在现有的旋转角度上进行旋转
transform.Rotate(new Vector3(x,y,z))
示例:transform.Rotate(Vector3.right * Time.deltaTime);