Author Topic: Linking other scripts to NGUI Elements  (Read 2797 times)

wpcain82

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 5
  • NGUI Noob
    • View Profile
Linking other scripts to NGUI Elements
« 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.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Linking other scripts to NGUI Elements
« Reply #1 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.  

wpcain82

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 5
  • NGUI Noob
    • View Profile
Re: Linking other scripts to NGUI Elements
« Reply #2 on: August 31, 2014, 10:23:05 AM »
I think I get it thanks for the quick reply!  ;D