1. We've introduced thread tags, search within a thread and similar thread search. Read more here.
    Dismiss Notice
  2. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice
  3. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  4. We've released our first Timeline Experimental Preview, our new tool for creating cutscenes and more! To check it out click here.
    Dismiss Notice
  5. Unity 5.5 is now released.
    Dismiss Notice
  6. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  7. Unity 5.6 beta is now available for download.
    Dismiss Notice

How do i access Text Object with the new UI???

Discussion in 'Unity UI' started by davem250, Aug 22, 2014.

  1. davem250

    davem250

    Joined:
    May 28, 2013
    Posts:
    186
    Hi there, i am currently using the open beta of V. 4.6 and i am in a predicament because i need to access the Text area of several text objects from the new 4.6 beta but i am totally clueless! i have tried to get access to the Text (Script) in MonoDevelop without any luck, and i have tried using guiText without any luck... what am i doing wrong??? and yes i need to modify some text inside the UI Text object in runtime in order for the player(s) to get a better experience :) Thanks for any kind of help i can get.
     
    MihailS likes this.
  2. Melang

    Melang

    Joined:
    Mar 30, 2014
    Posts:
    166
    I'm not sure it's the absolute best way to do it (I wish we could bind a public property to Text like we can do for sliders), but I do it like this:

    Code (csharp):
    1. using UnityEngine.UI;
    Code (csharp):
    1. public Text mytext;
    Code (csharp):
    1.  
    2. void Start () {
    3.  
    4.         mytext.text = "Hello world";
    5.  
    6.     }
    7.  
    Then in Inspector choose the right Text object for the public mytext field.
     
  3. davem250

    davem250

    Joined:
    May 28, 2013
    Posts:
    186
    Melang - Seriously thank you so much, i should have known that but i didn't even remotely think of that solution :O
    You're awesome Thank you so much for your help ;)
    Cheers,
     
    MihailS likes this.
  4. Sachs3n

    Sachs3n

    Joined:
    Aug 24, 2014
    Posts:
    2
    I missed that as well and was assuming the UI collections were included with the UnityEngine. Thanks for chipping in.
     
  5. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    2,228
    Code (JavaScript):
    1. var theTextComponent : UI.Text;
    2.  
    3. function WriteToTextComponentTextField () {
    4.      theTextComponent.text = "This is the actual field."
    5. }
     
  6. sgtmc50cal

    sgtmc50cal

    Joined:
    Jul 27, 2015
    Posts:
    1
    THANK YOU! I normally only see C# codes, but you actually gave the JS. Which is nice since that's all I am using for my project!