Author Topic: 'UILabel' is required to access non static member 'text'...  (Read 5415 times)

faceOFF

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
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 = "";
« Last Edit: July 31, 2012, 10:38:26 PM by faceOFF »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: 'UILabel' is required to access non static member 'text'...
« Reply #1 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. :|

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: 'UILabel' is required to access non static member 'text'...
« Reply #2 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.

faceOFF

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: 'UILabel' is required to access non static member 'text'...
« Reply #3 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!!!
« Last Edit: August 01, 2012, 03:27:00 AM by faceOFF »