我想在Unity3d中为Vector3类创建一个扩展方法.但我似乎没有得到它.这就是我所拥有的:
public static class ExtensionMethods{
public static Vector3 MaxValue(this Vector3 _vec3)
{
return new Vector3(float.MaxValue,float.MaxValue,float.MaxValue);
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想打一个Vector3.MaxValue
,就像float.MaxValue
用这行代码:
Vector3 closestPoint = Vector3.MaxValue;
Run Code Online (Sandbox Code Playgroud)
但后来我得到了这个错误:
error CS0117: `UnityEngine.Vector3' does not contain a definition for `MaxValue'
Run Code Online (Sandbox Code Playgroud)
我知道这会奏效:
Vector3 closestPoint = new Vector3().MaxValue();
Run Code Online (Sandbox Code Playgroud)
但后来我创建了2个新Vector3
实例.一个在MaxValue
通话中,一个在外面.是不是可以只使用这种代码制作一个并执行此操作:
Vector3 closestPoint = Vector3.MaxValue;
Run Code Online (Sandbox Code Playgroud)