Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    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,752
    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!
     
  7. Blasterano

    Blasterano

    Joined:
    Apr 9, 2020
    Posts:
    1
    what does right text mean