Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: ramones on April 24, 2012, 10:40:36 AM

Title: Registering OnClick event by code (code inside) not working.
Post by: ramones on April 24, 2012, 10:40:36 AM
Hi!,

I have been reading documentation and other threads on the subject but I can't get this working.

This is the code I'm using:

  1.  
  2. public void OnClick(GameObject go)
  3.         {
  4.                 Debug.Log ("lkjsfdjklfdsjlfdfdl");
  5.                
  6.                 if(go.name=="ReplayButton")
  7.                 {
  8.                         Debug.Log ("ReplayButton");
  9.                 }
  10.                 else if(go.name=="MenuButton")
  11.                 {
  12.                         Debug.Log ("MenuButton");
  13.                 }
  14.                 else if(go.name=="NextButton")
  15.                 {
  16.                         Debug.Log ("NextButton");
  17.                 }
  18.                
  19.                
  20.         }
  21.        
  22.         void OnEnable()
  23.         {
  24.                 GameObject go= GameObject.Find ("ReplayButton");
  25.                 UIEventListener.Add(go).onClick+=OnClick;
  26.                
  27.                 /*go= GameObject.Find ("MenuButton");
  28.                 UIEventListener.Get(go).onClick += OnClick;
  29.                
  30.                 go= GameObject.Find ("NextButton");
  31.                 UIEventListener.Get(go).onClick += OnClick;*/
  32.         }
  33.  
  34.  

I just have a mono behavior that contains a OnClick function that is set as the handler for OnClick event in the needed UIButton objects.

Could anybody guess why this is not working?.

Thanks in advance.
Title: Re: Registering OnClick event by code (code inside) not working.
Post by: ArenMook on April 24, 2012, 02:11:19 PM
What do you use to forward the event?
Title: Re: Registering OnClick event by code (code inside) not working.
Post by: ramones on April 24, 2012, 03:41:52 PM
I think I'm not following you. I thought that registering the event this way was what I need to do. Must I do anything else?

Ok it is working now. The problem was that the button was visible but because of the Z order it was no clickable (don't really understand this). Everything is on the same atlas, and it renders ok. I set z a bit more positive and I was able to click :/.

Thanks in advance.