Search Unity

  1. Engage, network and learn at Unite Austin 2017, Oct 3 - 5. Get your ticket today!
    Dismiss Notice
  2. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  3. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  6. Unity 2017.2 beta is now available for download.
    Dismiss Notice

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

Discussion in 'Unity UI & 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:
    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,360
    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!