Author Topic: using NGUI with javascript  (Read 10902 times)

hankthewhale

  • Guest
using NGUI with javascript
« on: September 24, 2012, 02:03:14 PM »
Forgive me if this is a huge oversight on my part, but I've looked everywhere for a tutorial that shows you how to get up and running using js and NGUI. I've found a ton of tutorials on how to change your atlas, add buttons to the scene, make them do cool animations, but absolutely nothing on how to make a button do something when it's clicked using js.

Using OnClick, I was able to get my button to print text to the screen but I want to know how to add more buttons. I'm sure there's a way of applying labels to a button to call in script so I have different buttons do different things but I can't find anything.

If anyone knows where I can find a tutorial on this, please let me know.

Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: using NGUI with javascript
« Reply #1 on: September 24, 2012, 03:23:33 PM »
NGUI is fully in C#, so that's why there are no UnityScript tutorials. NGUI supports JS, but as far as coding examples go, there isn't much to choose from. Perhaps others know a place. I believe even BurgZergArcade is all in C#.

hankthewhale

  • Guest
Re: using NGUI with javascript
« Reply #2 on: September 25, 2012, 06:33:18 AM »
Ah okay. This makes sense. Guess I finally have to start learning C#.

Komikus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: using NGUI with javascript
« Reply #3 on: October 06, 2012, 07:05:44 PM »
Ah okay. This makes sense. Guess I finally have to start learning C#.
Actually you don't. I got used to javascript so didn't have the will or the time to learn C#, but...

First you do this:


Then you can access all the Classes and reference the Components via GetComponent... reference either UIWidget or the Class name itself.

Hope this helps.
I'm currently having loads of fun using NGUI with Javascript and high praise to Tasharen for making it.

Gracore

  • Guest
Re: using NGUI with javascript
« Reply #4 on: October 10, 2012, 04:50:57 AM »
Actually you don't. I got used to javascript so didn't have the will or the time to learn C#, but...

First you do this:


Then you can access all the Classes and reference the Components via GetComponent... reference either UIWidget or the Class name itself.


Just wanted to say thanks so much for posting this image (how on earth did you find out that would work??), I was struggling like crazy trying to learn C# just for NGUI - I cant believe how simple that was to fix, really glad that I found this thread on here and you put that up.

Also 'ArenMook,' thanks so much for making NGUI, I spent a long time trying to get great results with Unity's built in gui, and waiting for the seemingly mythical Unity gui update. But I finally bought NGUI on its first madness sale, and just wow. Its so very good, I just wish I had bought it last year!

Thanks again guys!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,154
  • Toronto, Canada
    • View Profile
Re: using NGUI with javascript
« Reply #5 on: October 10, 2012, 09:52:32 AM »
That image is the very first thing you see when clicking on the "FAQ" post. :P

Gracore

  • Guest
Re: using NGUI with javascript
« Reply #6 on: October 12, 2012, 07:03:33 AM »

Haha, oh yeah! - Woops, my bad.  ;D

Magnotta

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: using NGUI with javascript
« Reply #7 on: June 20, 2014, 07:00:28 AM »
Sorry men for this question, how can i declare the UILabel in a Javascript after doing this? What's the problem in my script? If I use var myLabel : UILabel; I get this error "The name 'UILabel' does not denote a valid type ('not found')."  :( THANKS FOR THE HELP!


#pragma strict

var niceTime : String;
var seconds : int;
var myLabel : UILabel;
var myTimer : float = 80.0f;
var i : int;

function Update () {

for(i = 30; i > 0; i--){
         seconds = Mathf.FloorToInt(i);
         
         niceTime = String.Format("{00}", seconds);
         myLabel.text= niceTime;
}
}

Magnotta

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: using NGUI with javascript
« Reply #8 on: June 21, 2014, 07:28:57 AM »
Ok I've solved it, I placed in the Scripts folder in the NGUI folder instead of Plugins folder