Transform.rotation 旋转角度

var rotation : Quaternion

Description描述

The rotation of the transform in world space stored as a Quaternion.

在世界空间坐标物体变换的旋转角度作为Quaternion储存。

Unity stores rotations as Quaternions internally. To rotate an object, use Transform.Rotate. Use Transform.eulerAngles for setting the rotation as euler angles.

Untiy作为四元数内部储存旋转角度。旋转一个物体,使用Transform.Rotate,使用Transform.eulerAngles为设置作为欧拉角的旋转角度。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public void Awake() {
		transform.rotation = Quaternion.identity;
	}
}
// Reset the world rotation
//重设世界的旋转角度
transform.rotation = Quaternion.identity;

另一个例子:

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public float smooth = 2.0F;
	public float tiltAngle = 30.0F;
	void Update() {
		float tiltAroundZ = Input.GetAxis("Horizontal") * tiltAngle;
		float tiltAroundX = Input.GetAxis("Vertical") * tiltAngle;
		Quaternion target = Quaternion.Euler(tiltAroundX, 0, tiltAroundZ);
		transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
	}
}
// Smoothly tilts a transform towards a target rotation.
//平滑倾斜物体向一个target旋转
var smooth = 2.0;
var tiltAngle = 30.0;
function Update () {
	var tiltAroundZ = Input.GetAxis("Horizontal") * tiltAngle;
	var tiltAroundX = Input.GetAxis("Vertical") * tiltAngle;
	var target = Quaternion.Euler (tiltAroundX, 0, tiltAroundZ);
	// Dampen towards the target rotation
	//向target旋转阻尼
	transform.rotation = Quaternion.Slerp(transform.rotation, target,
	Time.deltaTime * smooth);;
}
最后修改:2010年12月18日 Saturday 23:37

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。