Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


implicit operator float4

Converts a Vector4 to a float4.
Read time 3 minutesLast updated 6 days ago

Definition

  • Type: Operator
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule

implicit operator float4(float)

Converts a Vector4 to a float4.
public static implicit operator float4(Vector4 v)

Parameters

The Vector4 to be converted to a float4.

Returns

Type

Description

float4The converted float4 result.

Remarks

An implicit conversion operator that converts an input Vector4 value to a float4.

implicit operator Vector4(Vector)

Converts a float4 to a Vector4.
public static implicit operator Vector4(float4 v)

Parameters

The float4 to be converted to a Vector4.

Returns

Type

Description

Vector4The converted Vector4 result.

Remarks

An implicit conversion operator that converts an input float4 value to a Vector4.

Examples

// Attach this script to a GameObject.using UnityEngine;using Unity.Mathematics;public class ExampleFloat4Conversion : MonoBehaviour{ void Start() { float4 a = new float4(1f, 2f, 3f, 4f); Debug.Log("Input float4 is: " + a.ToString()); // Implicitly convert Unity.Mathematics.float4 to UnityEngine.Vector4 Vector4 result = a; Debug.Log("Result Vector4 is: " + result.ToString()); }}

implicit operator Vector4(Vector)

Converts a Vector3 to a Vector4.
public static implicit operator Vector4(Vector3 v)

Parameters

The Vector3 to convert.

Returns

Type

Description

Vector4

Remarks

Vector3s can be implicitly converted to Vector4 (w is set to zero in the result).

Examples

using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ void Start() { // color as a Vector3 (red, green, blue) Vector3 color = new Vector3(1.0f, 0.25f, 0f); // This converts the Vector3 to a Vector4 with the w parameter set to 0 Vector4 colorWithOpacity = color; // set the opacity in the w parameter colorWithOpacity.w = 0.75f; }}

implicit operator Vector3(Vector)

Converts a Vector4 to a Vector3.
public static implicit operator Vector3(Vector4 v)

Parameters

The Vector4 to convert.

Returns

Type

Description

Vector3

Remarks

An implicit conversion of a Vector4 to a Vector3. The Vector4.w is discarded.

Examples

using UnityEngine;public class Example : MonoBehaviour{ void Start() { // Create and display a Vector4. Vector4 vector4; vector4 = new Vector4(1.0f, 2.0f, 3.0f, 4.0f); Debug.Log("Vector4: " + vector4); // Convert the Vector4 into a Vector3. Vector3 vector3; vector3 = vector4; // The 4.0f is not copied into the Vector3. // Show (1.0f, 2.0f, 3.0f). Debug.Log("Vector3: " + vector3); }}

implicit operator Vector4(Vector)

Converts a Vector2 to a Vector4.
public static implicit operator Vector4(Vector2 v)

Parameters

The Vector2 to convert.

Returns

Type

Description

Vector4

Remarks

Vector2s can be implicitly converted to Vector4 (z and w are set to zero in the result).

Examples

using UnityEngine;using System.Collections.Generic;public class ExampleScript : MonoBehaviour{ void Start() { Renderer renderer = GetComponent<Renderer>(); // Shader vectors are always defined as Vector4. // The value here is converted to a Vector4 from a Vector2. renderer.material.SetVector("_SomeVariable", Vector2.one); }}

implicit operator Vector2(Vector)

Converts a Vector4 to a Vector2.
public static implicit operator Vector2(Vector4 v)

Parameters

The Vector4 to convert.

Returns

Type

Description

Vector2

Remarks

An implicit conversion of a Vector4 to a Vector2. Vector4.z and Vector4.w are discarded.

Examples

using UnityEngine;public class Example : MonoBehaviour{ void Start() { // Create and display a Vector4. Vector4 vector4; vector4 = new Vector4(1.0f, 2.0f, 3.0f, 4.0f); Debug.Log("Vector4: " + vector4); // Convert the Vector4 into a Vector2. Vector2 vector2; vector2 = vector4; // The values 3.0f and 4.0f are not copied into the Vector2. // Show (1.0f, 2.0f). Debug.Log("Vector2: " + vector2); }}