This isnât an inheritance issue, but rather a namespace issue.
(note - in this context namespace refers to ANY name in your library. This includes both the ânamespaceâ at the top of your *.cs file, as well as the names of enums/classes/structs/etc. Itâs just like interface can refer to both the interface construct, and the actual interface of an object through which you access it.)
Static methods are static⌠they arenât necessarily inherited. Rather instead they exist in the scope of a namespace that happens to be in a class. Yes if you inherit from say MonoBehaviour you have direct access to a static method like âDestroyâ without having to say UnityEngine.Object.Destroy⌠but thatâs not necessarily because you inherited âDestroyâ in the sense of the OOP concept of inheritance. Itâs because your namespace overlaps with UnityEngine.Object where âDestroyâ is located. The compiler is just being nice to you is all. Itâs allowing you to shortcut say âDestroyâ instead of forcing you to type out the long form name, similar to how âusingâ lets you type shorthand namees rather than the long form name.
You are attempting to overwrite/replace a namespace. You canât do that.
You can create a new namespace. One option is to change the name of your static class like you do in your OP.
Another option is to create a new long namespace for your Debug static class to exist in. Changing the ânamespaceâ it is in to say:
namespace MyCustomNamespace
{
public static class Debug { }
}
This second option being what @Kurt-Dekker did.
But you canât have them both as âusingâ at the same time as youâll get an âambiguous referenceâ compiler error. The compiler doesnât know which class youâre talking about.
Thatâs the whole problem here⌠the namespace is how the compiler figures out what it is youâre referring to. If something already exists with the same namespace (such as UnityEngine.Debug), you canât replace that. It already exists. And the âusingâ statements is just there to ease the need to type out the long form name, but if youâre using 2 namespaces that have the same names in it⌠well this collision of namespace names result in that ambiguous error again. Is it âUnityEngine.Debugâ or âKurtDekkersLibrary.Debugâ?
Unfortunately this is just the nature of how C# deals with namespaces.
And again⌠has nothing to do with inheritance.
Also note that âExtensionMethodsâ donât work for static classes for similar reasons. All an ExtensionMethod is, is some syntax sugar. Youâre creating a static method that accepts an instance object⌠then the compiler just allows you to imply the namespace context as long as youâve applied the name to the end of an object that is the type the extensionmethod expects.
public static class MyExtMethods
{
public static Vector3 GetPos(this GameObject go) { return go.transform.position; }
}
//elsewhere
var go = GameObject.Find("SomeGO");
var a = MyExtMethods.GetPos(go);
var b = go.GetPos();
Both a and b are calling the same method.
âaâ is called using the traditional syntax of how a static method is called.
âbâ is called using syntax sugar that the compiler just unwraps and generates IL that looks/behaves identical to the way âaâ was called.