- Home /
Cant use Debug.Log
I have a static class that I want to log some info to the console.
Its a static class so I can't extend MonoBehavoir. I tried using Debug.Log() but it doesn't recognise it.
Is there a certain using I need to include?
I've seen examples where no using has been included in their class and they could use Debug.Log()
Does it still not work if you try: UnityEngine.Debug.Log("your message");
Perfecto! Thanks Dewald, Debug.Log() doesn't work but UnityEngine.Debug.Log(); works a treat. Thanks
Sorry for reviving a dead post, but I had this problem and it was a simple mistake for me, I had to import the UnityEngine - i.e.: "using UnityEngine;" at the top. Was this your issue, perhaps? Maybe you don't care at this point, since 2012, but in case anyone else like me stumbles on this issue, this was my fix.
Answer by tianjishu · Feb 22, 2012 at 03:00 AM
Debug is not static, so you can set up function for static function and class for unstatic function .
Debug is static:
static function Log (message : object) : void
Answer by Suyuanhan · Feb 22, 2012 at 04:30 AM
Must be in a static class? You could try: public class TestDebug : MonoBehaviour { public static void ShowDebug(){ Debug.Log("message"); }
and you can use it by: TestDebug.ShowDebug();
Static or not static doesn't matter. Debug.Log is a static function and can be called from anywhere.
Answer by samf1111 · Jul 26, 2021 at 07:26 PM
If you spelled MonoBehaviour the same way in your script as you did in your question, then the error is that you need to fix your spelling. That's all! :)