Legacy Documentation: Version 2018.2 (Go to current version)
LanguageEnglish
  • C#

Vector4.w

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public float w;

Description

W component of the vector.

using UnityEngine;

// Move and re-size a sphere. // Attach this script to a sphere added to the scene. // Use the x, y and z sliders to change the sphere position and // the w slider to change the scale of the sphere. // // View the changing x, y, z, and z values in the Inspector.

public class ExampleClass : MonoBehaviour { private Vector4 positionAndSize;

void Awake() { positionAndSize = new Vector4(0.0f, 0.0f, 0.0f, 1.0f); }

void Update() { transform.position = (Vector3)positionAndSize;

float a = positionAndSize.w; transform.localScale = new Vector3(a, a, a); }

void OnGUI() { GUI.skin.label.fixedHeight = 40; GUI.skin.label.fontSize = 24;

GUI.Label(new Rect(10, 10, 25, 0), "x:"); positionAndSize.x = GUI.HorizontalSlider(new Rect(60, 20, 200, 10), positionAndSize.x, -1.0f, 1.0f);

GUI.Label(new Rect(10, 50, 25, 0), "y:"); positionAndSize.y = GUI.HorizontalSlider(new Rect(60, 60, 200, 10), positionAndSize.y, -1.0f, 1.0f);

GUI.Label(new Rect(10, 90, 25, 0), "z:"); positionAndSize.z = GUI.HorizontalSlider(new Rect(60, 100, 200, 10), positionAndSize.z, -1.0f, 1.0f);

GUI.Label(new Rect(10, 130, 25, 0), "w:"); positionAndSize.w = GUI.HorizontalSlider(new Rect(60, 140, 200, 10), positionAndSize.w, 0.5f, 2.0f); } }
对文档有任何疑问,请移步至开发者社区提问,我们将尽快为您解答