UnityEngine.Vector2.Dot C# (CSharp) Method

Dot() public static method

public static Dot ( Vector2 a, Vector2 b ) : float
a Vector2
b Vector2
return float
		public static float Dot (Vector2 a, Vector2 b)
		{
			return a.x * b.x + a.y * b.y;
		}

Usage Example

Esempio n. 1
0
    public Vector2 GetLongLat(Vector3 point, GameObject gameObject)
    {
        Vector3 dirVector = point - gameObject.transform.position;
        Vector2 v1        = new Vector2(gameObject.transform.forward.x, gameObject.transform.forward.z);
        Vector2 v2        = new Vector2(dirVector.x, dirVector.z);

        //Debug.DrawRay(gameObject.transform.position, dirVector  * 20, Color.blue);

        float xAngle = Mathf.Acos(Vector2.Dot(v1.normalized, v2.normalized)) * Mathf.Rad2Deg;

        v1 = new Vector2(gameObject.transform.forward.y, gameObject.transform.forward.z);
        v2 = new Vector2(dirVector.y, dirVector.z);
        float yAngle = Mathf.Acos(Vector2.Dot(v1.normalized, v2.normalized)) * Mathf.Rad2Deg;

        var loc = gameObject.transform.rotation * point;

        if (loc.y < gameObject.transform.position.y)
        {
            yAngle *= -1.0f;
        }

        if (loc.x > gameObject.transform.position.x)
        {
            xAngle *= -1.0f;
        }

        return(new Vector2(xAngle, yAngle));
    }
All Usage Examples Of UnityEngine.Vector2::Dot