With that definition, you cannot use Vector3.SignedAngle. That function defines a method to be called on instances of Vector3, not a static extension of the Vector3 struct itself.
The only option for directly extending those Unity classes/structs would be to write a wrapper class that implements and extends the current functionality.
You can change your function like this to work properly:
You wrote an extension method, not a static method.
The this Vector3 vector3, references the Vector3 you’re calling the method on. The v in v.SignedAngle(v1, v2); And v1 and v2 are the 2 passed in as parameters.
Extension methods are a way to fake adding a method to the interface of an object.
If you want a static method, you just declare it static.
public static float SignedAngle(Vector3 v1, Vector3 v2)
{
var _angle = Vector3.Angle(v1, v2);
Vector3 _crossProduct = Vector3.Cross(v1, v2).normalized;
if (_crossProduct.z > 0) _angle *= -1;
return _angle;
}
This will mean that’s it’s a member of whatever class you added it to (I usually have a ‘VectorUtil’ class I do this with). You can’t insert static methods into existing classes.
Thank you guys. So I assume there’s no way to extend Vector3 class to make a Vector3.SignedAngle call, right? Unless you have the SDK available I guess…
Thanks again guys. Absolutely understood. I’m always a bit obsessed on trying to get the best organized code, but I assume I have to deal with this in a less elegant way.