Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


operator -(Vector2)

Negates a vector.
Read time 1 minuteLast updated 4 days ago

Definition

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

Parameters

The vector to negate.

Returns

Type

Description

Vector2The negative of the vector, returned as a Vector2 struct.

Remarks

Each component in the vector is negated, to obtain its negative value. The negative of a vector has the same magnitude but opposite direction.

Examples

using UnityEngine;public class Example : MonoBehaviour{ void Start() { // Create a vector. Vector2 A = new Vector2(1, 2); // Find the negative value. Vector2 B = - A; // Print the result. print(B + " is the negative of " + A); }}