用户工具

站点工具


侧边栏

script:unityengine:classes:transform:transform.rotation

Transform.rotation 旋转角度

JavaScript ⇒ var rotation: Quaternion;
C#

Description 描述

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

变换的旋转,在世界坐标空间储存为四元数。

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

Unity以四元数储存旋转角度。要旋转一个对象使用Transform.Rotate,使用Transform.eulerAngles以欧拉角设置旋转角度。

JavaScript:

	// Reset the world rotation
	transform.rotation = Quaternion.identity;

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    void Example() {
        transform.rotation = Quaternion.identity;
    }
}

另一个例子:

JavaScript:

	// Smoothly tilts a transform towards a target rotation.
	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
		transform.rotation = Quaternion.Slerp(transform.rotation, target,
		                               Time.deltaTime * smooth);;
	}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour 
                                    
script/unityengine/classes/transform/transform.rotation.txt · 最后更改: 2016/08/02 05:37 (外部编辑)