Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: michawtn on January 23, 2013, 09:50:09 AM

Title: Change state of Independed button (s) with an external JAVAscript.
Post by: michawtn on January 23, 2013, 09:50:09 AM
Try to make a several buttons working with an external JAVAscript.
Can anybody tell/help me what I’m doing wrong? :-\

Steps done before:

A. Create 2 buttons with the Widget Tool -> Template “Button” with Background “abcd.jpg”
B. Renamed the Button to “Button1” and “Button2”
C. Create a javascript buttonslection.js and attached this to " UI Root 2D"

Now I’m try to find out what button is pressed and make an action on the buttons..


  1. function Update ()
  2.                 {              
  3.                 if (UIEventListener.Get(GameObject.Find("Button1")).onClick != null)
  4.                         {
  5.                         Debug.Log ("do what you have todo is button 1 is pressed");
  6.                         // Need to force Button 2 into NOT highlighted (change UIButton state -> xx?)
  7.                         // Need to force Button 1 into (change UIButton state -> Pressed?)
  8.                         }
  9.                 if (UIEventListener.Get(GameObject.Find("Button2")).onClick != null)
  10.                         {
  11.                         Debug.Log ("do what you have todo is button 2 is pressed");
  12.                         // Need to force Button 1 into NOT highlighted (change UIButton state -> xx?)
  13.                         // Need to force Button 2 into (change UIButton state -> Pressed?)
  14.                         }
  15.                 }
  16.  

Title: Re: Change state of Independed button (s) with an external JAVAscript.
Post by: michawtn on January 24, 2013, 04:45:18 PM
Solved, It was to simple. Thanks Tasharen!

-> drag buttonslection.js to Panel
add to Button object from menu -> GameComponent -> NGUI -> Interaction -> Button Message
-> drag Panel into : Target :
-> Change funtion name : YourButtonFuntion
-> Trigger : OnClick

buttonslection.js
  1. Function YourButtonFuntion()
  2.   {
  3.   // Everything you like todo :P
  4.   }
  5.  
  6.  
  7.