Hey, I’m a newbie to Unity and loving it so far. However, I’m after some code to display debug text on my gameobjects (not the console) to display various variables associated with it. There doesn’t seem to be any command shipped with unity that takes care of this? I fear I’m missing something very obvious!
Cheers!
Hi Swagger,
you can see the current value of all public variables of the selected object in the inspector at runtime. If that is not enough write a Dump() method that logs the variables you’re interested in.
If you want to dump the whole object and it’s variables (don’t know how to), keep in mind that most objects have a lot of (inherited) properties…
there is a 3D-Text object, which you could use to display text right next to the game object, or you could use simple GUIText and recalculate it’s position each frame.
3D text object sounds like what I’m after (I’d prefer to have the text over the object rather than the inspector) - cant find any documentation on it though - can you point me towards it?
Cheers
make a script, drag it on the game object you want to debug. the script should contain something like this (i’m not testing this, so don’t be surprised if there are any mistakes in it)
var debugTooltip : TextMesh;
function Update() {
debugTooltip.text = "your debug code here";
}
create a new 3D-Text (GameObject->Create Other->3D Text) and place it where you want it to be, then drag the text onto the debugTooltip variable in the inspector.
let me know if you are running into any problems
the 3D text will act like a mesh object, so you can’t see it from far away or from the side. the GUIText solution is a bit more difficult to set up, but you won’t have visibility problems, unless you put too many of them in your scene
Wow, thanks for the reply, exactly what I needed. What a wonderful and supportive community!
THanks again