Print Anything to Screen

I have been desperatly trying to count a game object and its instantiated clones into an array, then print the result (counting) to the screen.

First I will ask about printing to screen, as simply printing text to screen doesn't even work. This is in javascript:

var helloText = "Hello World";

function OnGUI () 
{     
    GUI.Label (Rect (10, 10, 100, 20), helloText);
}

There is no result anywhere on any screen for this. Is there some option somewhere to enable GUI? Thanks.

OK question answered. In order for scripts to print to the editor.log file, the console, or the Screen, they must be attached to a gameobject.

Thanks guys.

You have to attach scripts to objects if you want them to do anything; your script works fine if you attach it to something.

Debug.Log("My Text"); should print to the console. Try doing it in the gameObject awake method to test:

void Awake()
{
Debug.Log("My Text");
}

[HELP] I am having a problem with my script as it will not print to console no matter what.
-I made sure every icon in the right hand corner was turned on.
-I made sure there was a GameObject in place.

  • I saved the script before execution.

What happened was that the unity console was working fine until all of a sudden unity froze on me for at least 20 min so I forced closed the program by restarting my computer. After that the unity console would not print anything. Nothing is wrong with my code I wrote exactly this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NumberWizard : MonoBehaviour {

// Use this for initialization
void Start () {
    print("Hello");
}

// Update is called once per frame
void Update () {
	
}

}
This code is all correct but the unity console wont print it.
I apologize for the lack of screen shots since I do not know how.

Can anyone help?

Hey man, Make it a String, then output the string in a text.

    var text:String[]=[
        "HOW EVER",
        "MUCH STUFF",
        "YOU WANT",
        "GOES HERE"] ;

function BeginPage(width,height) {
    GUILayout.BeginArea(Rect((Screen.width-width)/2,(Screen.height-height)/2,width,height));
}

function ShowText() {
    BeginPage(300,300);
    for (var texts in text) {
        GUILayout.Label(credit);
    }
    for (var texts in crediticons) {
        GUILayout.Label(texts);
    }
    EndPage();
}

function Update () 
{
  ShowText();

}

That should work good enough!

Oh yes, this is altered from: http://www.unifycommunity.com/wiki/index.php?title=PauseMenu