Hello Guest

Author Topic: Can't make UIItem events to fire my code  (Read 4119 times)

griden

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 15
    • View Profile
Can't make UIItem events to fire my code
« on: February 06, 2014, 11:24:43 am »
So I have a regular button (from the demo prefab) and attached the following custom script to it:

Code: [Select]

        private tk2dUIItem uiItem;

void Start () {
uiItem = GetComponent<tk2dUIItem>();
}

void OnEnable()
{
uiItem.OnDown += ButtonDown;
}

void ButtonDown()
{
Debug.Log("Button Down!");
}

... And clicking it doesn't do anything. The collider is ok, and the tk2dCamera has a tk2dUICamera component attached. What am I missing is the question? :) Thanks.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Can't make UIItem events to fire my code
« Reply #1 on: February 06, 2014, 09:50:06 pm »
Does the button actually press if you click on it? Is it too close to the camera that it is clipping with the near clip plane? Do you have a negative near clip plane (there was a bug which will be fixed in tk2d 2.4, for now you should just move your camera back and use a positive near clip plane if this is the case).

griden

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Can't make UIItem events to fire my code
« Reply #2 on: February 07, 2014, 11:24:19 am »
Oh yes, the button does the scale down animation and the clicking sound. And the near clipping plane is positive 0.3, far is 25 (took the values from the tutorial). The button itself is at Z: -2, and the camera - at Z: -10. And they all look pretty far from each other in 3D view.

UPDATE: it works now. I just dragged the same object to the Target field (under 'Send Message' in the inspector) and simply picked the method from the list. Object sending message to itself. Still wondering why the code approach didn't work, but everything is fine now.

Thanks again!


edo

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Can't make UIItem events to fire my code
« Reply #3 on: October 23, 2014, 07:41:02 am »
Hi,
Just got into the same problem. so i post the solution if it gonna help someone in the future...

use:
void Awake()

instead of:
void Start()