Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


operator -(Vector2, Vector2)

Subtracts one vector from another.
Read time 1 minuteLast updated 5 days ago

Definition

  • Type: Operator
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule
public static Vector2 operator -(Vector2 a, Vector2 b)

Parameters

The vector to subtract
b
from.

The vector to subtract from
a
.

Returns

Type

Description

Vector2The difference between the two vectors, returned as a Vector2 struct.

Remarks

Subtracts each component of
b
from
a
.

Examples

using UnityEngine;public class Example : MonoBehaviour{ void Start() { // Create two vectors. Vector2 A = new Vector2(1, 2); Vector2 B = new Vector2(3, 2); // Subtract vector B from vector A. Vector2 C = A - B; // Print the result. print(C); }}