Unity has my classname, can i do anything?

I’m trying to make a class called Debug, with various special debugging functions that will be useful to my project.

well that sure didnt work, it already exists. M>y next logiccal thought then, is to try to extend/inherit from the existing one. But i’m told that debug is a sealed class :frowning:

must i just select another name? i was really fond of that one.

What? It should work to call your class Debug. There is no Debug class in the global namespace, unity’s is in the UnityEngine namespace.

2 Likes

You could always place it in your own namespace.

namespace MyNamespace
{
    public class MyClass
    {
        ...
    }
}

Then you reference it as MyNamspace.MyClass

4 Likes

To add to my initial post, if you are using UnityEngine, and the Debug class is in the global namespace, then there’s a good chance of receiving an ambiguous compilation error. To resolve the error, simply do as follows:

global::smile:ebug.Log();

And to call the unity one

UnityEngine.Debug.Log();
1 Like

WARNING!
If you do it this way, be careful not to place using MyNamespace at the top. If you do this and you try to call Debug, the compiler won’t know which one you are trying to call. This is a perfect example of why REAL C++ coders NEVER use the directive usingnamespace std; at the top because of this very problem.

If you do implement your own class that Unity currently has as one of its classes then either remove using UnityEngine or call the namespace directly when you want to call your Debug class via MyNamespace.Debug.

1 Like

Nah, nothing to worry about. As I stated above, the compiler will warn of the ambiguouse reference. Have you not ever heard of CS0104??

http://msdn.microsoft.com/en-us/library/e094swa1(v=vs.90).aspx

Just type out the fully qualified name and you’re good to go.

Its exactly what I said…

http://msdn.microsoft.com/en-us/library/aa712965(v=vs.71).aspx

This is C#, not C++

Same thing.

to add to the suggestions of the other folks. You can also explicitly tell the compiler wich Debug version to use without typing the full qualified name all the time.
Example

using UnityEngine;
using MyNameSpace;
using Debug = MyNameSpace.Debug;

Debug.Log() // now refferes to MyNameSpace.Debug.Log()
4 Likes

What he means is that there is no need to panic over such a small issue because C# is not a ticking time bomb like C++. The issue can be resolved quite easily and the solution is described in the very link that you posted.