版本: Unity 6 (6000.0)
语言English
  • C#

Quaternion.w

建议更改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法采纳所有提交内容,但我们确实会阅读用户提出的每一项更改建议,并在适用的情况下进行更新。

关闭

提交失败

由于某些原因,您的更改建议无法提交。请<a>稍后再试</a>。感谢您抽出时间帮助我们提高 Unity 文档的质量。

关闭

取消

切换到手册
public float w;

描述

四元数的 W 分量。请勿直接修改四元数。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

// Quaternion-w script example // Create a Sphere and apply a texture to help the orientation be recognised. // At each second the sphere is rotated and the quaternion is displayed.

public class ExampleClass : MonoBehaviour { private float timeDelay = 0.0f; private Quaternion q; private string label = "";

void Awake() { // Add a line that passes through the y axis of the sphere and make // the line as a child. GameObject line = GameObject.CreatePrimitive(PrimitiveType.Cube); line.transform.localScale = new Vector3(0.05f, 1.5f, 0.05f); line.transform.parent = gameObject.transform; }

void Update() { if (timeDelay > 1.0f) { Vector3 v;

// generate a random euler angle v.x = Random.Range(0.0f, 360.0f); v.y = Random.Range(0.0f, 360.0f); v.z = Random.Range(0.0f, 360.0f);

// convert the euler into a quaternion q = Quaternion.Euler(v);

// and apply it to the sphere transform.rotation = q;

// generate a string label = q.ToString("f3");

// and start another 1 second delay timeDelay = 0.0f; } timeDelay += Time.deltaTime; }

// display the quaternion as a string void OnGUI() { GUI.skin.label.fixedHeight = 40; GUI.skin.label.fontSize = 24; GUI.Label(new Rect(10, 10, 400, 30), label); } }