Search Unity

Chaning Text via Script

Discussion in 'Scripting' started by Kooth, Mar 1, 2015.

  1. Kooth

    Kooth

    Joined:
    Feb 23, 2015
    Posts:
    53
    Hello !
    I try to use the 4.6 ui system ,what's wrong on my script o_O.

    Code (JavaScript):
    1. import UnityEngine.UI ;
    2. import UnityEngine.UI.Text ;
    3.  
    4. public var test : Text ;
    5.  
    6. function Start () {
    7.  
    8. test = GetComponent.<Text>() ;
    9. }
    10.  
    11. function Update () {
    12.  
    13. test = "caca" ;
    14. }
    Cannot convert 'String' to 'UnityEngine.UI.Text'.

    thanks
     
  2. Kooth

    Kooth

    Joined:
    Feb 23, 2015
    Posts:
    53

    1. Code (JavaScript):
      1. import UnityEngine.UI ;
      2. import UnityEngine.UI.Text ;
      3. public var test : Text ;
      4. function Start () {
      5. test = GetComponent.<Text>() ;
      6. }
      7. function Update () {
      8. test.text = "caca" ;
      9. }
     
  3. CWolf

    CWolf

    Joined:
    Oct 24, 2011
    Posts:
    106