unity使用localEulerAngles,unity中rotation赋值和Rotate进行旋转的区别

Transform组件的关于旋转转向方面的API解析-GAD腾讯游戏开发者平台.localRotation 自身旋转角度
var localRotation :
Description描述
The rotation of the transform relative to the parent transform's rotation.
物体变换的旋转角度相对于父级的物体变换的旋转角度。
Unity stores rotations as Quaternions internally. To rotate an object, use .
for modifying the rotation as euler angles.
Untiy作为四元数内部储存旋转角度。旋转一个物体,使用,使用为设置作为欧拉角的旋转角度。
using UnityE
using System.C
public class example :
public void Awake() {
transform.localRotation = Quaternion.
// Set the rotation to be the same as the parent
//设置旋转角度同父级一样。
transform.localRotation = Quaternion.
本脚本参考基于Unity 3.4.1f5英文部分版权属&公司所有,中文部分&
版权所有,未经许可,严禁转载 。扫一扫,访问微社区
后使用快捷导航没有帐号?
签到成功!您今天第{todayrank}个签到,签到排名竞争激烈,记得每天都来签到哦!已连续签到:{constant}天,累计签到:{days}天
Unity 实现编辑器下的鼠标看模型功能到运行状态 鼠标右键旋转 中间缩放平移功能 ... . ...
using UnityEusing System.C//这个脚本绑到相机上public class CameraControll : MonoBehaviour{& & public float near = 20.0f;& & public float far = 100.0f;& & public float sensitivityX = 2f;& & public float sensitivityY = 2f;& & public float sensitivetyZ = 0f;& & public float sensitivetyMove = 10f;& & public float sensitivetyMouseWheel = 5f;& & public int speed = 1;& & public C& & void Awake()& & {& & & & camera = transform.GetComponent&Camera&();& & }& & void Update()& & {& & & & /*& & & & //w键前进 && & & & if (Input.GetKey(KeyCode.W))& & & & {& & & & & & transform.Translate(new Vector3(0, 0, speed * Time.deltaTime));& & & & }& & & & //s键后退 && & & & if (Input.GetKey(KeyCode.S))& & & & {& & & & & & transform.Translate(new Vector3(0, 0, -1 * speed * Time.deltaTime));& & & & }& & & & //a键后退 && & & & if (Input.GetKey(KeyCode.A))& & & & {& & & & & & transform.Translate(new Vector3(-1 * speed, 0, 0 * Time.deltaTime));& & & & }& & & & //d键后退 && & & & if (Input.GetKey(KeyCode.D))& & & & {& & & & & & transform.Translate(new Vector3(speed, 0, 0 * Time.deltaTime));& & & & }& & & & */& & & & if (Input.GetMouseButton(2))& & & & {& & & & & & transform.Translate(Vector3.left * Input.GetAxis("Mouse X"));& & & & & & transform.Translate(Vector3.down * Input.GetAxis("Mouse Y"));& & & & }& & & & // 滚轮实现镜头缩进和拉远 && & & & if (Input.GetAxis("Mouse ScrollWheel") != 0)&& & & & {&& & & & & & //camera.fieldOfView =this.camera.fieldOfView - Input.GetAxis("Mouse ScrollWheel")*sensitivetyMouseW&& & & & & & //camera.fieldOfView = Mathf.Clamp(this.camera.fieldOfView, near, far);&& & & & & & camera.transform.Translate(Vector3.forward * Input.GetAxis("Mouse ScrollWheel") * sensitivetyMouseWheel);& & & & }&& & & &&& & & & //鼠标实现视角转动,类似第一人称视角 && & & & if (Input.GetMouseButton(1)) && & & & { &&& & & & & & float rotationX = Input.GetAxis("Mouse X") * sensitivityX;& & & & & & float rotationY = Input.GetAxis("Mouse Y") * sensitivityY; && & & & & & transform.Rotate(-0, rotationX, 0);& & & & & & transform.Rotate(-rotationY, 0, 0);& & & & & & transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, transform.localEulerAngles.y,0);& & & & }& & & & //键盘按钮←和→实现视角水平旋转 && & & &&& & & & if (Input.GetAxis("Horizontal")!=0)&& & & & {&& & & & & & float rotationZ=Input.GetAxis("Horizontal") * sensitivetyZ;&& & & & & & transform.Rotate(0, 0, rotationZ); && & & & }&& & }}
作者的其他最新博客
评论 ( 个评论)}

我要回帖

更多关于 unity rotation赋值 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信