Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


implicit operator Vector2

Converts a Vector3 to a Vector2.
Read time 1 minuteLast updated 4 days ago

Definition

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

implicit operator Vector2(Vector)

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

Parameters

Returns

Type

Description

Vector2

Remarks

A Vector3 can be implicitly converted into a Vector2. (The z is discarded).

Examples

using UnityEngine;public class ExampleScript : MonoBehaviour{ void Start() { Vector2 v2 = new Vector2(1, 2); Debug.Log("Vector2 is: " + v2); // convert v2 to v3 Vector3 v3 = v2; Debug.Log("Vector3 is: " + v3); // convert v3 to new Vector3 Debug.Log("Set v3 to (3, 4, 5)"); v3 = new Vector3(3, 4, 5); // convert v3 to v2 v2 = v3; Debug.Log("Vector2 is: " + v2); }}

implicit operator Vector3(Vector)

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

Parameters

The Vector2 to convert.

Returns

Type

Description

Vector3

Remarks

A Vector2 can be implicitly converted into a Vector3. (The z is set to zero in the result).

Examples

using UnityEngine;public class ExampleScript : MonoBehaviour{ void Start() { Vector2 v2 = new Vector2(1, 2); Debug.Log("Vector2 is: " + v2); // convert v2 to v3 Vector3 v3 = v2; Debug.Log("Vector3 is: " + v3); // convert v3 to new Vector3 Debug.Log("Set v3 to (3, 4, 5)"); v3 = new Vector3(3, 4, 5); // convert v3 to v2 v2 = v3; Debug.Log("Vector2 is: " + v2); }}