Search Unity

create GUI.Label and then access to it..

Discussion in 'Scripting' started by ineteye, Oct 9, 2012.

  1. ineteye

    ineteye

    Joined:
    Sep 12, 2012
    Posts:
    35
    Hi!
    So need to create GUI.Label and then access to it...

    first script :

    test.js

    Code (csharp):
    1. var style : GUIStyle;
    2. public var SCORE = "0";
    3.  
    4. function OnGUI ()
    5. {
    6.     style.fontSize=18;
    7.     style.normal.textColor=Color.red;  
    8.     GUI.Label (Rect (Screen.width*0.2, Screen.height*0.15, 100, 20), SCORE,style);
    9. }
    10.  
    test_access.js

    Code (csharp):
    1. function Start()
    2. {
    3.     var LOAD : test;
    4.     LOAD = GetComponent(test);
    5.     LOAD.SCORE="1";
    6. }
    So this solution does not work...
     
    Last edited: Oct 9, 2012
  2. Landern

    Landern

    Joined:
    Dec 21, 2008
    Posts:
    354
    is test.js of type instantiate?
     
  3. ineteye

    ineteye

    Joined:
    Sep 12, 2012
    Posts:
    35
    sorry )) Fixed problem .. script originally was instantiate.js, not test.js
     
  4. ineteye

    ineteye

    Joined:
    Sep 12, 2012
    Posts:
    35
    So what i am doing wrong???
     
  5. Democre

    Democre

    Joined:
    Mar 31, 2010
    Posts:
    345
    What doesn't work about that solution? Are there errors or the score is just not updating?
    Are test and test_access scripts both attached to the same game object?
     
  6. ineteye

    ineteye

    Joined:
    Sep 12, 2012
    Posts:
    35
    test and test_access - both different object.. error NullReferenceException: Object reference not set to an instance of an object