- Home /
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.
i've tried print() and debug.log (only to editor.log). nothing prints anywhere, not even to the editor.log file, I'll see my script in the editor log run, and nothing else. Nothing prints to console either.
Getting rather dismayed that its this complex to simply print text to the screen.
Answer by Eric5h5 · Dec 05, 2010 at 11:11 PM
You have to attach scripts to objects if you want them to do anything; your script works fine if you attach it to something.
Yea it displays now in the console, but still nothing on screen.
Sorry Eric, I think I totally read your answer wrong...
You're right, heres a sample project: http://rapidshare.com/files/435300496/New_Unity_Project_31.rar
I think I read his code wrong...
I apologize I got lost in doing stuff, soon as I tied it to the object it worked. Feel kinda silly!
Answer by boymeetsrobot · Dec 05, 2010 at 10:44 PM
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");
}
is that for Csharp? cause that just has a whole ton of errors with it in js.
Answer by Justin Warner · Dec 06, 2010 at 06:05 AM
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
That won't work at all; you can't call OnGUI functions from Update, plus you have no EndPage function.
Works for me in my game...
And if you goto that link I put, it also has the endpage, I just did it quickly, and I think I know what you mean, but eh, it gets pretty close to what he wants.
No, it simply will not work to call OnGUI functions from Update. The code you posted will only generate an error (assu$$anonymous$$g you fix the missing stuff).
Answer by Angelo101 · Dec 28, 2017 at 11:17 PM
[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?
Your answer
Follow this Question
Related Questions
what is the correct way to display text on screen 1 Answer
How to Position a GuiText Prefab at Center of Screen 2 Answers
Gizmo-like GUi text? 2 Answers
Fit GUIText in every resolution 3 Answers