Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: wpcain82 on August 28, 2014, 01:44:36 PM

Title: Linking other scripts to NGUI Elements
Post by: wpcain82 on August 28, 2014, 01:44:36 PM
I have been able to link some script methds to the NGUI elememts suck as : UILabel pulling an int from another script etc. I am trying to figure out how to use certain logic on the UI elements"

For example I have a timer script that counts down in my GameManger script and I want a NGUI window to pop up once it reaches 0. I am assuming I can call some function on a UIElement that will activate the Element right? Also say for a bool once true a certain GUI button is enabled. Any ideas on how this is done?

Sorry for the noob question.
Title: Re: Linking other scripts to NGUI Elements
Post by: Nicki on August 28, 2014, 04:09:08 PM
You can access any component by using GetComponent<MYTYPE>() on their gameobject, which you can set up as a reference in the inspector if you make their field public or [SerializeField].

  1. class MyScript : Monobehaviour{
  2.  
  3. [SerializeField] UILabel _label; //set in inspector
  4. public void UpdateLabel(string text) {
  5. _label.text = text;
  6. }
  7. }
  8.  
Title: Re: Linking other scripts to NGUI Elements
Post by: wpcain82 on August 31, 2014, 10:23:05 AM
I think I get it thanks for the quick reply!  ;D