Search Unity

Edit UI via script....

Discussion in 'UGUI & TextMesh Pro' started by lsmdev, Sep 1, 2014.

  1. lsmdev

    lsmdev

    Joined:
    Aug 6, 2014
    Posts:
    1
    How I can edit the UI elements via script (in my case c#)..? For example: if I want to edit the text property of a UI text what must I do..?
     
  2. Nothke

    Nothke

    Joined:
    Dec 2, 2012
    Posts:
    112
    (for C#) First, you must include
    Code (CSharp):
    1. using UnityEngine.UI;
    in your script, then obtain your text, for example using
    Code (CSharp):
    1. public Text yourText;
    and attach your text in the inspector.
    Finally, you can set it using
    Code (CSharp):
    1. yourText.text = "Your string";
    Also, check out this tutorial http://unity3d.com/learn/tutorials/modules/beginner/ui/ui-text
    There is a scripting example on the end.
     
    Last edited: Sep 1, 2014