Search Unity

How to output text to the screen.

Discussion in 'Immediate Mode GUI (IMGUI)' started by Checksum, Apr 18, 2010.

  1. Checksum

    Checksum

    Joined:
    Apr 18, 2010
    Posts:
    19
    Man I feel like such a retard. I searched the forum but I'm not quite sure what to look for.

    How do I simply output text to the screen? I'm doing some network code and just want to output some 2D text to the screen starting from the top left down.

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Test: MonoBehaviour {
    5.  
    6.     // Use this for initialization
    7.     void Start () {
    8.                
    9.     //OUTPUT TEXT TO THE TOP LEFT OF SCREEN
    10.     //OUTPUT TEXT TO THE TOP LEFT OF SCREEN
    11.     //OUTPUT TEXT TO THE TOP LEFT OF SCREEN
    12.     //OUTPUT TEXT TO THE TOP LEFT OF SCREEN
    13.     //OUTPUT TEXT TO THE TOP LEFT OF SCREEN
    14.        
    15.     }
    16.    
    17.     // Update is called once per frame
    18.     void Update () {
    19.    
    20.     }
    21.  
    22.     void OnGUI() {
    23.  
    24.         GUI.Button (Rect (10,10,150,20), "Skinned Button");
    25.        
    26.     }
    27.    
    28. }
    I looked up the UnityGUI, but anytime I put the onGui function in my code it gives an error.
     
  2. Quietus2

    Quietus2

    Joined:
    Mar 28, 2008
    Posts:
    2,058
    A label is a far better device for displaying text than a button.

    In terms of the error you say you get but for some reason didn't include, try adding the 'new' keyword before your rect.

    Code (csharp):
    1.  GUI.Button (new Rect (10,10,150,20), "Skinned Button");
     
  3. Checksum

    Checksum

    Joined:
    Apr 18, 2010
    Posts:
    19
    Thanks man that worked.