Print() Function - Build and Run will not display it!

Hey,

I am quite new still to Unity.

However, if you do a Build and Run of your Scene etc the window will not display the Print() function with my variables.

Is there code to do that - so that the Build and Run will display my Print Variables?

Thanks.

if by Print you mean debug, that would only work in the editor.

Oh OK. Thanks!

So how do I get text to show in the REAL game then (Java Script preferred)?

Generally speaking, you use a GUIText item :

http://unity3d.com/support/documentation/ScriptReference/Component-guiText.html

There are a couple of useful scripts on the wiki :

http://www.unifycommunity.com/wiki/index.php?title=MessageList

Hope this helps :slight_smile:

Currently advanced for my skill, but I do understand most of it.

Thanks for the link!

ERROR

MissingComponentException: There is no ‘GUIText’ attached to the “Empty” game object, but a script is trying to access it.
You probably need to add a GUIText to the game object “Empty”. Or your script needs to check if the component is attached before using it.
Basic_Programming(JAVA).Main () (at Assets/Basic_Programming(JAVA).js:9)

Any ideas?

I did add it under my object - I mean, parented it (named ‘Empty’) and it still wont clear that error!

It does work, but what does the Error mean?

Thanks.

attach a GUIText component to your gameobject where the script is attached

Both the script and a GUIText should be added to that GameObject, you can’t put them in two different objects.

GUIText is pretty outdated though, real GUI is the way to go.

simply write

//Add text when you click the mouse
//Warning, all code typed in browser, cannot guarantee that it works
var mytextlabel = "Hello";

function OnGUI () {
    //Display some text
    GUILayout.Label (mytextlabel);
}

function Update () {
    if (Input.GetKey ("mouse 0")) {
         //Add text to the label, \n is a line break
         mytextlabel += "someone clicked the mouse\n";
    }
}

The script on the wiki is a bit more advanced though.

If you want to see the log (Debug.Log calls) from a build (game), you can open the Player Log, click the “Open Player Log” button located at the top-right corner of the Console window (the one where you see all errors and such).

Ahh, SOLVED.

I had the scripts attached to TWO objects…

I only have it attached now to the GUI.

Thanks!

There’s your problem :wink: