Version: 2017.4
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

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 var w: float;
public float w;

Description

W component of the vector.

#pragma strict
// 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.
private var positionAndSize: Vector4;
function Awake() {
	positionAndSize = new Vector4(0.0f, 0.0f, 0.0f, 1.0f);
}
function Update() {
	transform.position = Vector3positionAndSize;
	var a: float = positionAndSize.w;
	transform.localScale = new Vector3(a, a, a);
}
function 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);
}
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); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961