- Home /
The question is answered, right answer was accepted
Debug.Log a gameobject in C ?
Hello i need to make something very easy in java but can't do it in C. Just debug log 2 value, bounds and gameobject.
Why this don't work ?
public GameObject debuggo = new GameObject(); //( don't)
public GameObject debuggo =GameObject;// ( don't)
public GameObject debuggo =gameObject;// ( don't)
public GameObject debuggo =This;// ( don't)
Debug.Log(bounds);// ( work )
Debug.Log(debuggo);// ( don't )
Debug.Log(bounds , debuggo);// (don't ) -----> I want something like this to have the name of gameobject that i debug.
Debug.Log(bounds , gameObject); //(don't )
Debug.Log(bounds , GameObject); //(don't )
Answer by Cherno · Jul 23, 2017 at 07:00 PM
The Debug.Log method accepts a string as a parameter. Things like intergers are converted automatically but you can't just "add" things with a comma because a comma used like this makes no sense to the method. You have to insert it between the parts of the string with the plus symbol and make the comma itself a string by putting it between double quotation mark.
Debug.Log(bounds +", " + gameObject);
Also, you mean C#. C is a different programming language.
Uhm, you're right that Debug.Log only accept one object as message but it does accept a second parameter which is of type UnityEngine.Object. This is a "context object". The point of that parameter is that when you click on the message in the console, Unity will "ping" that content object. So if it's a gameobject in the scene, that object will be highlighted yellow for a sec.
Also the first parameter type is not string but "object". So the method internally convert the object passed into a string. You're right that if you want to actually "print" several values at once you have to form a single string as message. However you can always pass a context as well.
Answer by agencebrunel · Jul 23, 2017 at 07:20 PM
I have delet my var gameobject declaration, ( no need that ) and writte
Debug.Log(bounds +", " + gameObject);
As you said Cherno and work. Thanks :)