UNITY 5.2 Vector2 Structure

Source: Internet
Author: User
Tags float max string format unity 5
Static variables: All read-only properties, abbreviations for some special vectorspublic static Vector2 up {get;}
An abbreviation for Vector2 (0, 1)

public static Vector2 down {get;}
An abbreviation for Vector2 (0,-1)

public static Vector2 left {get;}
An abbreviation for Vector2 (-1, 0)

public static Vector2 right {get;}
An abbreviation for Vector2 (1, 0)

public static Vector2 one {get;}
An abbreviation for VECTOR2 (1, 1)

public static Vector2 zero {get;}
An abbreviation for Vector2 (0, 0)

constructor Function:Public Vector2 (float x, float y);
Description: The value that is required to pass in the vector, or the default constructor, because the object is a value type because it is a struct

Public variables:Public Vector2 normalized {get;}
Description: Returns the unit vector of a vector, returning a new vector without changing the vector value. If the vector is too small, it may return a 0 vector.

Public float magnitude {get;}
Description: Returns the length of the vector, if only the comparison vector size should be used Sqrmagnitude

Public float sqrmagnitude {get;}
Description: Calculates the square of the vector length quickly, so the comparison vector size uses this property

Public float This[int index] {get; set;}
Description: Use the indexer to access the value of x = [0],y = [1]

public float y;
public float x;
Description: The two coordinate values of the vector

Public function:public void Normalize ();
Description: The current vector will be normalized, changing the current vector's value, and substituting the attribute if you do not want to change it. If it's too small, return 0 vectors.

public void Set (float new_x, float new_y);
Description: Sets the X, y value of the vector that already exists

public void scale (Vector2 scale);
Description: Enlarges this vector by scale

public override string ToString ();
public string ToString (string format);
Description: Returns the string format of a vector

static function:public static float Angle (Vector2 from, Vector2 to);
Description: Gets the angle between two vectors [0, 180], without order

public static Vector2 clampmagnitude (Vector2 vector, float maxLength);
Description: Returns a vector of the same unit vector as the vector, with a size of maxLength

public static float Distance (Vector2 A, Vector2 b);
Description: Returns the distance of the A vector from the B vector. (A-B) magnitude

public static float Dot (Vector2 lhs, Vector2 RHS);
Description: Return LHS * RHS

public static Vector2 Lerp (Vector2 A, Vector2 B, float t);
public static Vector2 lerpunclamped (Vector2 A, Vector2 B, float t);
Description: A vector is inserted in Linear a B, and T [0,1] denotes [a, b]

public static Vector2 Max (Vector2 lhs, Vector2 RHS);
public static Vector2 Min (Vector2 lhs, Vector2 RHS);
Description: A new vector consisting of the maximum (minimum) values in two vectors

public static Vector2 Movetowards (Vector2, Vector2 target, float maxdistancedelta);
Note: Move the current in the direction vector with target, no more than target Maxdistancedelta

public static Vector2 Reflect (Vector2 indirection, Vector2 innormal);
Description: Map the indirection to the Innormal

public static Vector2 scale (Vector2 A, Vector2 b);
Description: Gets a vector of the product of the elements of a B vector

public static Vector2 Smoothdamp (Vector2 current, Vector2 target, ref Vector2 currentvelocity, float smoothtime);
public static Vector2 Smoothdamp (Vector2 current, Vector2 target, ref Vector2 currentvelocity, float smoothtime, float max Speed);
public static Vector2 Smoothdamp (Vector2 current, Vector2 target, ref Vector2 currentvelocity, float smoothtime, float max Speed, float deltatime);
Note: Gradually move a vector to the target location
Current: coordinates
Target: Destination coordinates
Currentvelocity: The speed at which each call to this function gets
Smoothtime: About the time spent, the smaller the value, the greater the speed
Maxspeed: Limit the maximum speed
Deltatime: Invokes the event interval, which defaults to Time.deltatime.

operator Overloading: all operator overloads are in a static function, and all operations do not affect the original vectorpublic static Vector2 operator-(Vector2 a);
Description: Reverse the vector

public static Vector2 operator-(Vector2 A, Vector2 b);
Description: Vector A-B

public static Vector2 operator * (float D, Vector2 a);
public static Vector2 operator * (Vector2 A, float d);
Description: The vector is multiplied by the real number

public static Vector2 operator/(Vector2 A, float d);
Description: Divide the vector by the real number

public static Vector2 operator + (Vector2 A, Vector2 b);
Description: vector addition

public static BOOL operator = = (Vector2 lhs, Vector2 RHS);
public static bool Operator! = (Vector2 lhs, Vector2 RHS);
Description: Determine if vectors are equal

public static implicit operator Vector3 (Vector2 v);
public static implicit operator Vector2 (Vector3 v);
Description: Implicit conversion conversions between 2D and 3D vectors
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.