Version: 2022.1
언어: 한국어
public float w ;

설명

W component of the Quaternion. Do not directly modify quaternions.

A quaternion can represent a 3D rotation and is defined by 4 real numbers. x, y and z represent a vector. w is a scalar that stores the rotation around the vector. More details about quaternions can be located at https://scriptinghelpers.org/blog/how-to-think-about-quaternions.

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); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961