Tuesday, August 7, 2018

Vector3 Extensions

public static Vector3 xyz (this Vector3 v, float x, float y, float z) {
    v.x = x;    v.y = y;   v.z = z;
    return v;
}
public static Vector3 xy (this Vector3 v, float x, float y) {
    v.x = x;   v.y = y;
    return v;
}
public static Vector3 xz (this Vector3 v, float x, float z) {
    v.x = x;   v.z = z;
    return v;
}

//calling it
Vector3 v = Vector3.zero;
v.xz(5f,10f);


//============================

public static Vector3 ChangeX (this Transform transform, float x) {
    Vector3 position = transform.position;
    position.x = x;
    transform.position = position;
    return position;
}
// Do the same for ChangeY and ChangeZ
// ...

// Old version
Vector3 position = transform.position;
position.x = 10;
transform.position = position;

// New version
transform.ChangeX(10);

Unity3D - Vector3 to Quaternion


static vector3 quaternion
vector3.zero (0, 0, 0) (0.0, 0.0, 0.0, 1.0)
vector3.back (0, 0, -1) (0.0, 0.0, -0.5, 0.9)
vector3.down (0, -1, 0) (0.0, -0.5, 0.0, 0.9)
vector3.forward (0, 0, 1) (0.0, 0.0, 0.5, 0.9)
vector3.left (-1, 0, 0) (-0.5, 0.0, 0.0, 0.9)
vector3.one (1, 1, 1) (0.6, 0.2, 0.2, 0.8)
vector3.right (1, 0, 0) (0.5, 0.0, 0.0, 0.9)
vector3.up (0, 1, 0) (0.0, 0.5, 0.0, 0.9)