Search Unity

Update GUI Component with a script

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

  1. wbl1


    Apr 22, 2009
    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.
    Last edited: Mar 16, 2015
  2. psyydack


    Aug 30, 2013