Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: faceOFF on July 31, 2012, 10:21:33 PM

Title: 'UILabel' is required to access non static member 'text'...
Post by: faceOFF on July 31, 2012, 10:21:33 PM
I have a script in Java:
  1. var input : GameObject;
  2.  
  3. function Awake ()
  4. {
  5.         input.GetComponent(onSubmitJS).string = ToString(UILabel.text);
  6. }

In summary: Assets/Scripts/onSubmitLabelNameJS.js(5,66): BCE0020: An instance of type 'UILabel' is required to access non static member 'text'.

In general, I need GetComponent from Input / UILabel in my script "SubmitLeaderBoard.js"
Maybe can I do it in C#?
Then how do GetComponent from C# to JS?

Rephrase the question: How do I send OnSubmit "Player Name" from the Input / UILabel
in my script "SubmitLeaderBoard.js" in the string variable "username"?
  1. public var username:String = "";
Title: Re: 'UILabel' is required to access non static member 'text'...
Post by: ArenMook on July 31, 2012, 10:40:46 PM
I don't know unity script. Only C#. In C#, instead of doing this:

  1. UILabel.text
You need to do something like this:
  1. GetComponent<UILabel>().text
UILabel is a type, and you need an instance of this type.

I explained this yesterday in another thread: http://www.tasharen.com/forum/index.php?topic=109.msg6107#msg6107

This question falls into "how do I use Unity" category. :|
Title: Re: 'UILabel' is required to access non static member 'text'...
Post by: JRoch on August 01, 2012, 12:55:25 AM
If I'm reading what he's trying to do right (looks like that jscript is attached to the same gameobject that has the UILabel attached to it) then in C# it would look something like this:

  1. input.GetComponent<onSubmitJS>.string = this.GameObject.GetComponent<UILabel>.text;
  2.  

The should be enough of a hint for how to transcode it back to jscript.
Title: Re: 'UILabel' is required to access non static member 'text'...
Post by: faceOFF on August 01, 2012, 03:20:25 AM
This question falls into "how do I use Unity" category. :|
You like to complicate things?
It is sad to meet such support from the developer ..

  1. input.GetComponent<onSubmitJS>.string = this.GameObject.GetComponent<UILabel>.text;
  2.  
The should be enough of a hint for how to transcode it back to jscript.

Thanks for the hint! Everything works fine in JS, and sends a string from UIInput.cs in SubmitLeaderBoard.js!!!
That is can come in handy (UJS):
  1. public var leaderBoard : GameObject;
  2. public var uILabel : GameObject;
  3.  
  4. function OnSubmit ()
  5. {
  6.         leaderBoard.GetComponent(SubmitLeaderBoard).username = uILabel.GetComponent(UILabel).text;
  7. }
All has appeared so simply!
JRoch, thanks a lot again!!!