Search Unity

Update GUI Component with a script

Discussion in 'UGUI & TextMesh Pro' started by wbl1, Mar 16, 2015.

  1. wbl1

    wbl1

    Joined:
    Apr 22, 2009
    Posts:
    159
    I feel pretty silly asking this question, but I am just starting with the new GUI and I'd like to be able to update the text in a Text component via script.

    How do you get a handle on the component and modify the text that is displayed in the UI? What is displayed when you set the component up is not necessarily what you'd want to display at runtime obviously ...

    I have a panel, with a Text component as a child of that panel. I would think I could grab the component and modify the text something like this ...

    GetComponent(Text).text="some new text";

    but I see nothing like this anywhere in the doco ... can anyone help please?

    Edit: the solution is here ... if this is actually documented somewhere, I'd appreciate it if someone could tell me where to go.

    http://answers.unity3d.com/questions/777335/46-ui-changing-the-text-component-via-script.html
     
    Last edited: Mar 16, 2015
  2. psyydack

    psyydack

    Joined:
    Aug 30, 2013
    Posts:
    93