Search Unity

In game text for debug values not working.

Discussion in '2D' started by Carlos_7x, Feb 15, 2017.

  1. Carlos_7x

    Carlos_7x

    Joined:
    Jan 19, 2017
    Posts:
    16
    Hi people!
    I really don't know what I'm doing wrong, since I'm using a UI Text and trying to set a default text but it just won't appear.

    I tried almost everything with no succeed. Do you know something related? If not, I want to ask, is there other way to handle this? I know I can print the values in console, but I prefer to have the values in the game screen rather than looking at console every now and then.

    Thanks!!!
     
  2. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    make ui text gameobject. Add lines in your script with values:
    Code (CSharp):
    1. public GameObject myTextObject;
    2. Text myTextComponent;
    reference it to text component on ui text object
    Code (CSharp):
    1. void Start () {
    2. myTextComponent = myTextObject.GetComponent <Text>();
    3. }
    change later "text" variable with string variable
    Code (CSharp):
    1. myTextComponent.text = stringVariable;
    2. //you can convert you values to string with
    3. myTextComponent.text = myValue.toString();
    4.  
    put ui textobject in the new scripts field
     
    Carlos_7x likes this.
  3. Carlos_7x

    Carlos_7x

    Joined:
    Jan 19, 2017
    Posts:
    16
    Hey, thanks!.