I am trying to override what the * operator does for type Vector2 (which is undefined). Can this not be done?
I don’t think you can do this. See also this StackOverflow answer. I would do:
public static class Vector2Override
{
public static Vector2 MultiplyByVector(this Vector2 a, Vector2 b)
{
return new Vector2(a.x * b.x, a.y * b.y);
}
}
and use it with:
Vector2 vector1 = new Vector2(1, 2);
Vector2 vector2 = new Vector2(3, 4);
Vector2 vector3 = vector1.MultiplyByVector(vector2);