Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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

Discussion in 'UGUI & TextMesh Pro' 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:
    4
    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:
    3,033
    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!
     
unityunity